Refactor session initialization in SessionRoutes to improve prompt handling
- Changed the order of operations in session initialization to first create/get the SDK session with the original prompt. - Introduced a new step to clean the prompt of privacy tags after determining the session ID. - Updated logging to reflect the new flow and ensure clarity on session creation and prompt number calculation.
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -501,24 +501,27 @@ export class SessionRoutes extends BaseRouteHandler {
|
|||||||
|
|
||||||
const store = this.dbManager.getSessionStore();
|
const store = this.dbManager.getSessionStore();
|
||||||
|
|
||||||
// Step 1: Strip privacy tags from prompt BEFORE storing
|
// Step 1: Create/get SDK session (idempotent INSERT OR IGNORE)
|
||||||
// This prevents <private> content from being persisted to sdk_sessions.user_prompt
|
const sessionDbId = store.createSDKSession(claudeSessionId, project, prompt);
|
||||||
const cleanedPrompt = stripMemoryTagsFromPrompt(prompt);
|
|
||||||
|
|
||||||
// Step 2: Create/get SDK session with CLEANED prompt (idempotent INSERT OR IGNORE)
|
logger.info('HTTP', 'SessionRoutes: createSDKSession returned', {
|
||||||
const sessionDbId = store.createSDKSession(claudeSessionId, project, cleanedPrompt);
|
sessionDbId,
|
||||||
|
claudeSessionId
|
||||||
|
});
|
||||||
|
|
||||||
// Step 3: Get next prompt number from user_prompts count
|
// Step 2: Get next prompt number from user_prompts count
|
||||||
const currentCount = store.getPromptNumberFromUserPrompts(claudeSessionId);
|
const currentCount = store.getPromptNumberFromUserPrompts(claudeSessionId);
|
||||||
const promptNumber = currentCount + 1;
|
const promptNumber = currentCount + 1;
|
||||||
|
|
||||||
logger.info('HTTP', 'SessionRoutes: Session initialization', {
|
logger.info('HTTP', 'SessionRoutes: Calculated promptNumber', {
|
||||||
sessionDbId,
|
sessionDbId,
|
||||||
claudeSessionId,
|
|
||||||
promptNumber,
|
promptNumber,
|
||||||
currentCount
|
currentCount
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Step 3: Strip privacy tags from prompt
|
||||||
|
const cleanedPrompt = stripMemoryTagsFromPrompt(prompt);
|
||||||
|
|
||||||
// Step 4: Check if prompt is entirely private
|
// Step 4: Check if prompt is entirely private
|
||||||
if (!cleanedPrompt || cleanedPrompt.trim() === '') {
|
if (!cleanedPrompt || cleanedPrompt.trim() === '') {
|
||||||
logger.debug('HOOK', 'Session init - prompt entirely private', {
|
logger.debug('HOOK', 'Session init - prompt entirely private', {
|
||||||
|
|||||||
Reference in New Issue
Block a user