fix: resolve search, database, and docker bugs (#2079)
* fix: resolve search, database, and docker bugs (#1913, #1916, #1956, #1957, #2048) - Fix concept/concepts param mismatch in SearchManager.normalizeParams (#1916) - Add FTS5 keyword fallback when ChromaDB is unavailable (#1913, #2048) - Add periodic WAL checkpoint and journal_size_limit to prevent unbounded WAL growth (#1956) - Add periodic clearFailed() to purge stale pending_messages (#1957) - Fix nounset-safe TTY_ARGS expansion in docker/claude-mem/run.sh Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: prevent silent data loss on non-XML responses, add queue info to /health (#1867, #1874) - ResponseProcessor: mark messages as failed (with retry) instead of confirming when the LLM returns non-XML garbage (auth errors, rate limits) (#1874) - Health endpoint: include activeSessions count for queue liveness monitoring (#1867) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * fix: cache isFts5Available() at construction time Addresses Greptile review: avoid DDL probe (CREATE + DROP) on every text query. Result is now cached in _fts5Available at construction. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -56,13 +56,14 @@ else
|
||||
fi
|
||||
|
||||
# Pick -it only when a TTY is attached (keeps non-interactive callers working).
|
||||
# Initialize with a no-op flag so the array is never empty (nounset-safe).
|
||||
TTY_ARGS=()
|
||||
[[ -t 0 && -t 1 ]] && TTY_ARGS=(-it)
|
||||
|
||||
# NOT `exec` — we want the EXIT trap above to run and remove $CREDS_FILE
|
||||
# after the container exits. Running docker as a child keeps the shell
|
||||
# alive long enough for the trap to fire.
|
||||
docker run --rm "${TTY_ARGS[@]}" \
|
||||
docker run --rm ${TTY_ARGS[@]+"${TTY_ARGS[@]}"} \
|
||||
"${CREDS_MOUNT_ARGS[@]}" \
|
||||
-v "$HOST_MEM_DIR:/home/node/.claude-mem" \
|
||||
"$TAG" \
|
||||
|
||||
@@ -6,7 +6,7 @@ ${o.stack}`:` ${o.message}`:this.getLevel()===0&&typeof o=="object"?u=`
|
||||
`,"utf8")}catch(T){process.stderr.write(`[LOGGER] Failed to write to log file: ${T instanceof Error?T.message:String(T)}
|
||||
`)}else process.stderr.write(g+`
|
||||
`)}debug(e,t,s,n){this.log(0,e,t,s,n)}info(e,t,s,n){this.log(1,e,t,s,n)}warn(e,t,s,n){this.log(2,e,t,s,n)}error(e,t,s,n){this.log(3,e,t,s,n)}dataIn(e,t,s,n){this.info(e,`\u2192 ${t}`,s,n)}dataOut(e,t,s,n){this.info(e,`\u2190 ${t}`,s,n)}success(e,t,s,n){this.info(e,`\u2713 ${t}`,s,n)}failure(e,t,s,n){this.error(e,`\u2717 ${t}`,s,n)}timing(e,t,s,n){this.info(e,`\u23F1 ${t}`,n,{duration:`${s}ms`})}happyPathError(e,t,s,n,o=""){let m=((new Error().stack||"").split(`
|
||||
`)[2]||"").match(/at\s+(?:.*\s+)?\(?([^:]+):(\d+):(\d+)\)?/),u=m?`${m[1].split("/").pop()}:${m[2]}`:"unknown",E={...s,location:u};return this.warn(e,`[HAPPY-PATH] ${t}`,E,n),o}},_=new Z;var Xt={};function wt(){return typeof __dirname<"u"?__dirname:(0,f.dirname)((0,he.fileURLToPath)(Xt.url))}var $t=wt();function Ft(){if(process.env.CLAUDE_MEM_DATA_DIR)return process.env.CLAUDE_MEM_DATA_DIR;let r=(0,f.join)((0,ee.homedir)(),".claude-mem"),e=(0,f.join)(r,"settings.json");try{if((0,P.existsSync)(e)){let{readFileSync:t}=require("fs"),s=JSON.parse(t(e,"utf-8")),n=s.env??s;if(n.CLAUDE_MEM_DATA_DIR)return n.CLAUDE_MEM_DATA_DIR}}catch{}return r}var N=Ft(),y=process.env.CLAUDE_CONFIG_DIR||(0,f.join)((0,ee.homedir)(),".claude"),cs=(0,f.join)(y,"plugins","marketplaces","thedotmack"),us=(0,f.join)(N,"archives"),ms=(0,f.join)(N,"logs"),_s=(0,f.join)(N,"trash"),ps=(0,f.join)(N,"backups"),ls=(0,f.join)(N,"modes"),Es=(0,f.join)(N,"settings.json"),Oe=(0,f.join)(N,"claude-mem.db"),gs=(0,f.join)(N,"vector-db"),Pt=(0,f.join)(N,"observer-sessions"),te=(0,f.basename)(Pt),Ts=(0,f.join)(y,"settings.json"),fs=(0,f.join)(y,"commands"),Ss=(0,f.join)(y,"CLAUDE.md");function Ae(r){(0,P.mkdirSync)(r,{recursive:!0})}function Re(){return(0,f.join)($t,"..")}var ye=require("crypto");var Ce=require("os"),Ie=L(require("path"),1);var j=require("fs"),X=L(require("path"),1),M={isWorktree:!1,worktreeName:null,parentRepoPath:null,parentProjectName:null};function Ne(r){let e=X.default.join(r,".git"),t;try{t=(0,j.statSync)(e)}catch(u){return u instanceof Error&&u.code!=="ENOENT"&&console.warn("[worktree] Unexpected error checking .git:",u),M}if(!t.isFile())return M;let s;try{s=(0,j.readFileSync)(e,"utf-8").trim()}catch(u){return console.warn("[worktree] Failed to read .git file:",u instanceof Error?u.message:String(u)),M}let n=s.match(/^gitdir:\s*(.+)$/);if(!n)return M;let i=n[1].match(/^(.+)[/\\]\.git[/\\]worktrees[/\\]([^/\\]+)$/);if(!i)return M;let a=i[1],d=X.default.basename(r),m=X.default.basename(a);return{isWorktree:!0,worktreeName:d,parentRepoPath:a,parentProjectName:m}}function Le(r){return r==="~"||r.startsWith("~/")?r.replace(/^~/,(0,Ce.homedir)()):r}function jt(r){if(!r||r.trim()==="")return _.warn("PROJECT_NAME","Empty cwd provided, using fallback",{cwd:r}),"unknown-project";let e=Le(r),t=Ie.default.basename(e);if(t===""){if(process.platform==="win32"){let n=r.match(/^([A-Z]):\\/i);if(n){let i=`drive-${n[1].toUpperCase()}`;return _.info("PROJECT_NAME","Drive root detected",{cwd:r,projectName:i}),i}}return _.warn("PROJECT_NAME","Root directory detected, using fallback",{cwd:r}),"unknown-project"}return t}function se(r){let e=jt(r);if(!r)return{primary:e,parent:null,isWorktree:!1,allProjects:[e]};let t=Le(r),s=Ne(t);if(s.isWorktree&&s.parentProjectName){let n=`${s.parentProjectName}/${e}`;return{primary:n,parent:s.parentProjectName,isWorktree:!0,allProjects:[s.parentProjectName,n]}}return{primary:e,parent:null,isWorktree:!1,allProjects:[e]}}var Ht=3e4;function H(r,e,t){return(0,ye.createHash)("sha256").update([r||"",e||"",t||""].join("\0")).digest("hex").slice(0,16)}function G(r,e,t){let s=t-Ht;return r.prepare("SELECT id, created_at_epoch FROM observations WHERE content_hash = ? AND created_at_epoch > ?").get(e,s)}function re(r){if(!r)return[];try{let e=JSON.parse(r);return Array.isArray(e)?e:[String(e)]}catch{return[r]}}var h="claude";function Gt(r){return r.trim().toLowerCase().replace(/\s+/g,"-")}function D(r){if(!r)return h;let e=Gt(r);return e?e==="transcript"||e.includes("codex")?"codex":e.includes("cursor")?"cursor":e.includes("claude")?"claude":e:h}function De(r){let e=["claude","codex","cursor"];return[...r].sort((t,s)=>{let n=e.indexOf(t),o=e.indexOf(s);return n!==-1||o!==-1?n===-1?1:o===-1?-1:n-o:t.localeCompare(s)})}function Bt(r,e){return{customTitle:r,platformSource:e?D(e):void 0}}var B=class{db;constructor(e=Oe){e!==":memory:"&&Ae(N),this.db=new ve.Database(e),this.db.run("PRAGMA journal_mode = WAL"),this.db.run("PRAGMA synchronous = NORMAL"),this.db.run("PRAGMA foreign_keys = ON"),this.initializeSchema(),this.ensureWorkerPortColumn(),this.ensurePromptTrackingColumns(),this.removeSessionSummariesUniqueConstraint(),this.addObservationHierarchicalFields(),this.makeObservationsTextNullable(),this.createUserPromptsTable(),this.ensureDiscoveryTokensColumn(),this.createPendingMessagesTable(),this.renameSessionIdColumns(),this.repairSessionIdColumnRename(),this.addFailedAtEpochColumn(),this.addOnUpdateCascadeToForeignKeys(),this.addObservationContentHashColumn(),this.addSessionCustomTitleColumn(),this.addSessionPlatformSourceColumn(),this.addObservationModelColumns(),this.ensureMergedIntoProjectColumns(),this.addObservationSubagentColumns()}initializeSchema(){this.db.run(`
|
||||
`)[2]||"").match(/at\s+(?:.*\s+)?\(?([^:]+):(\d+):(\d+)\)?/),u=m?`${m[1].split("/").pop()}:${m[2]}`:"unknown",E={...s,location:u};return this.warn(e,`[HAPPY-PATH] ${t}`,E,n),o}},_=new Z;var jt={};function wt(){return typeof __dirname<"u"?__dirname:(0,f.dirname)((0,he.fileURLToPath)(jt.url))}var $t=wt();function Ft(){if(process.env.CLAUDE_MEM_DATA_DIR)return process.env.CLAUDE_MEM_DATA_DIR;let r=(0,f.join)((0,ee.homedir)(),".claude-mem"),e=(0,f.join)(r,"settings.json");try{if((0,P.existsSync)(e)){let{readFileSync:t}=require("fs"),s=JSON.parse(t(e,"utf-8")),n=s.env??s;if(n.CLAUDE_MEM_DATA_DIR)return n.CLAUDE_MEM_DATA_DIR}}catch{}return r}var N=Ft(),y=process.env.CLAUDE_CONFIG_DIR||(0,f.join)((0,ee.homedir)(),".claude"),cs=(0,f.join)(y,"plugins","marketplaces","thedotmack"),us=(0,f.join)(N,"archives"),ms=(0,f.join)(N,"logs"),_s=(0,f.join)(N,"trash"),ps=(0,f.join)(N,"backups"),ls=(0,f.join)(N,"modes"),Es=(0,f.join)(N,"settings.json"),Oe=(0,f.join)(N,"claude-mem.db"),gs=(0,f.join)(N,"vector-db"),Pt=(0,f.join)(N,"observer-sessions"),te=(0,f.basename)(Pt),Ts=(0,f.join)(y,"settings.json"),fs=(0,f.join)(y,"commands"),Ss=(0,f.join)(y,"CLAUDE.md");function Ae(r){(0,P.mkdirSync)(r,{recursive:!0})}function Re(){return(0,f.join)($t,"..")}var ye=require("crypto");var Ce=require("os"),Ie=L(require("path"),1);var X=require("fs"),j=L(require("path"),1),M={isWorktree:!1,worktreeName:null,parentRepoPath:null,parentProjectName:null};function Ne(r){let e=j.default.join(r,".git"),t;try{t=(0,X.statSync)(e)}catch(u){return u instanceof Error&&u.code!=="ENOENT"&&console.warn("[worktree] Unexpected error checking .git:",u),M}if(!t.isFile())return M;let s;try{s=(0,X.readFileSync)(e,"utf-8").trim()}catch(u){return console.warn("[worktree] Failed to read .git file:",u instanceof Error?u.message:String(u)),M}let n=s.match(/^gitdir:\s*(.+)$/);if(!n)return M;let i=n[1].match(/^(.+)[/\\]\.git[/\\]worktrees[/\\]([^/\\]+)$/);if(!i)return M;let a=i[1],d=j.default.basename(r),m=j.default.basename(a);return{isWorktree:!0,worktreeName:d,parentRepoPath:a,parentProjectName:m}}function Le(r){return r==="~"||r.startsWith("~/")?r.replace(/^~/,(0,Ce.homedir)()):r}function Xt(r){if(!r||r.trim()==="")return _.warn("PROJECT_NAME","Empty cwd provided, using fallback",{cwd:r}),"unknown-project";let e=Le(r),t=Ie.default.basename(e);if(t===""){if(process.platform==="win32"){let n=r.match(/^([A-Z]):\\/i);if(n){let i=`drive-${n[1].toUpperCase()}`;return _.info("PROJECT_NAME","Drive root detected",{cwd:r,projectName:i}),i}}return _.warn("PROJECT_NAME","Root directory detected, using fallback",{cwd:r}),"unknown-project"}return t}function se(r){let e=Xt(r);if(!r)return{primary:e,parent:null,isWorktree:!1,allProjects:[e]};let t=Le(r),s=Ne(t);if(s.isWorktree&&s.parentProjectName){let n=`${s.parentProjectName}/${e}`;return{primary:n,parent:s.parentProjectName,isWorktree:!0,allProjects:[s.parentProjectName,n]}}return{primary:e,parent:null,isWorktree:!1,allProjects:[e]}}var Ht=3e4;function H(r,e,t){return(0,ye.createHash)("sha256").update([r||"",e||"",t||""].join("\0")).digest("hex").slice(0,16)}function G(r,e,t){let s=t-Ht;return r.prepare("SELECT id, created_at_epoch FROM observations WHERE content_hash = ? AND created_at_epoch > ?").get(e,s)}function re(r){if(!r)return[];try{let e=JSON.parse(r);return Array.isArray(e)?e:[String(e)]}catch{return[r]}}var h="claude";function Gt(r){return r.trim().toLowerCase().replace(/\s+/g,"-")}function D(r){if(!r)return h;let e=Gt(r);return e?e==="transcript"||e.includes("codex")?"codex":e.includes("cursor")?"cursor":e.includes("claude")?"claude":e:h}function De(r){let e=["claude","codex","cursor"];return[...r].sort((t,s)=>{let n=e.indexOf(t),o=e.indexOf(s);return n!==-1||o!==-1?n===-1?1:o===-1?-1:n-o:t.localeCompare(s)})}function Bt(r,e){return{customTitle:r,platformSource:e?D(e):void 0}}var B=class{db;constructor(e=Oe){e!==":memory:"&&Ae(N),this.db=new ve.Database(e),this.db.run("PRAGMA journal_mode = WAL"),this.db.run("PRAGMA synchronous = NORMAL"),this.db.run("PRAGMA foreign_keys = ON"),this.db.run("PRAGMA journal_size_limit = 4194304"),this.initializeSchema(),this.ensureWorkerPortColumn(),this.ensurePromptTrackingColumns(),this.removeSessionSummariesUniqueConstraint(),this.addObservationHierarchicalFields(),this.makeObservationsTextNullable(),this.createUserPromptsTable(),this.ensureDiscoveryTokensColumn(),this.createPendingMessagesTable(),this.renameSessionIdColumns(),this.repairSessionIdColumnRename(),this.addFailedAtEpochColumn(),this.addOnUpdateCascadeToForeignKeys(),this.addObservationContentHashColumn(),this.addSessionCustomTitleColumn(),this.addSessionPlatformSourceColumn(),this.addObservationModelColumns(),this.ensureMergedIntoProjectColumns(),this.addObservationSubagentColumns()}initializeSchema(){this.db.run(`
|
||||
CREATE TABLE IF NOT EXISTS schema_versions (
|
||||
id INTEGER PRIMARY KEY,
|
||||
version INTEGER UNIQUE NOT NULL,
|
||||
@@ -752,7 +752,7 @@ ${o.stack}`:` ${o.message}`:this.getLevel()===0&&typeof o=="object"?u=`
|
||||
ORDER BY ss.created_at_epoch DESC
|
||||
LIMIT ?
|
||||
`).all(...e,...e,...s?[s]:[],t.sessionCount+ie)}function qt(r){return r.replace(/\//g,"-")}function Vt(r){if(!r.includes('"type":"assistant"'))return null;let e=JSON.parse(r);if(e.type==="assistant"&&e.message?.content&&Array.isArray(e.message.content)){let t="";for(let s of e.message.content)s.type==="text"&&(t+=s.text);if(t=t.replace(ke,"").trim(),t)return t}return null}function Yt(r){for(let e=r.length-1;e>=0;e--)try{let t=Vt(r[e]);if(t)return t}catch(t){t instanceof Error?_.debug("WORKER","Skipping malformed transcript line",{lineIndex:e},t):_.debug("WORKER","Skipping malformed transcript line",{lineIndex:e,error:String(t)});continue}return""}function Kt(r){try{if(!(0,Y.existsSync)(r))return{userMessage:"",assistantMessage:""};let e=(0,Y.readFileSync)(r,"utf-8").trim();if(!e)return{userMessage:"",assistantMessage:""};let t=e.split(`
|
||||
`).filter(n=>n.trim());return{userMessage:"",assistantMessage:Yt(t)}}catch(e){return e instanceof Error?_.failure("WORKER","Failed to extract prior messages from transcript",{transcriptPath:r},e):_.warn("WORKER","Failed to extract prior messages from transcript",{transcriptPath:r,error:String(e)}),{userMessage:"",assistantMessage:""}}}function me(r,e,t,s){if(!e.showLastMessage||r.length===0)return{userMessage:"",assistantMessage:""};let n=r.find(d=>d.memory_session_id!==t);if(!n)return{userMessage:"",assistantMessage:""};let o=n.memory_session_id,i=qt(s),a=we.default.join(y,"projects",i,`${o}.jsonl`);return Kt(a)}function Pe(r,e){let t=e[0]?.id;return r.map((s,n)=>{let o=n===0?null:e[n+1];return{...s,displayEpoch:o?o.created_at_epoch:s.created_at_epoch,displayTime:o?o.created_at:s.created_at,shouldShowLink:s.id!==t}})}function _e(r,e){let t=[...r.map(s=>({type:"observation",data:s})),...e.map(s=>({type:"summary",data:s}))];return t.sort((s,n)=>{let o=s.type==="observation"?s.data.created_at_epoch:s.data.displayEpoch,i=n.type==="observation"?n.data.created_at_epoch:n.data.displayEpoch;return o-i}),t}function Xe(r,e){return new Set(r.slice(0,e).map(t=>t.id))}function je(){let r=new Date,e=r.toLocaleDateString("en-CA"),t=r.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}).toLowerCase().replace(" ",""),s=r.toLocaleTimeString("en-US",{timeZoneName:"short"}).split(" ").pop();return`${e} ${t} ${s}`}function He(r){return[`# [${r}] recent context, ${je()}`,""]}function Ge(){return[`Legend: \u{1F3AF}session ${A.getInstance().getActiveMode().observation_types.map(t=>`${t.emoji}${t.id}`).join(" ")}`,"Format: ID TIME TYPE TITLE","Fetch details: get_observations([IDs]) | Search: mem-search skill",""]}function Be(){return[]}function We(){return[]}function qe(r,e){let t=[],s=[`${r.totalObservations} obs (${r.totalReadTokens.toLocaleString()}t read)`,`${r.totalDiscoveryTokens.toLocaleString()}t work`];return r.totalDiscoveryTokens>0&&(e.showSavingsAmount||e.showSavingsPercent)&&(e.showSavingsPercent?s.push(`${r.savingsPercent}% savings`):e.showSavingsAmount&&s.push(`${r.savings.toLocaleString()}t saved`)),t.push(`Stats: ${s.join(" | ")}`),t.push(""),t}function Ve(r){return[`### ${r}`]}function Ye(r){return r.toLowerCase().replace(" am","a").replace(" pm","p")}function Ke(r,e,t){let s=r.title||"Untitled",n=A.getInstance().getTypeIcon(r.type),o=e?Ye(e):'"';return`${r.id} ${o} ${n} ${s}`}function Je(r,e,t,s){let n=[],o=r.title||"Untitled",i=A.getInstance().getTypeIcon(r.type),a=e?Ye(e):'"',{readTokens:d,discoveryDisplay:m}=k(r,s);n.push(`**${r.id}** ${a} ${i} **${o}**`),t&&n.push(t);let u=[];return s.showReadTokens&&u.push(`~${d}t`),s.showWorkTokens&&u.push(m),u.length>0&&n.push(u.join(" ")),n.push(""),n}function Qe(r,e){return[`S${r.id} ${r.request||"Session started"} (${e})`]}function w(r,e){return e?[`**${r}**: ${e}`,""]:[]}function ze(r){return r.assistantMessage?["","---","","**Previously**","",`A: ${r.assistantMessage}`,""]:[]}function Ze(r,e){return["",`Access ${Math.round(r/1e3)}k tokens of past work via get_observations([IDs]) or mem-search skill.`]}function et(r){return`# [${r}] recent context, ${je()}
|
||||
`).filter(n=>n.trim());return{userMessage:"",assistantMessage:Yt(t)}}catch(e){return e instanceof Error?_.failure("WORKER","Failed to extract prior messages from transcript",{transcriptPath:r},e):_.warn("WORKER","Failed to extract prior messages from transcript",{transcriptPath:r,error:String(e)}),{userMessage:"",assistantMessage:""}}}function me(r,e,t,s){if(!e.showLastMessage||r.length===0)return{userMessage:"",assistantMessage:""};let n=r.find(d=>d.memory_session_id!==t);if(!n)return{userMessage:"",assistantMessage:""};let o=n.memory_session_id,i=qt(s),a=we.default.join(y,"projects",i,`${o}.jsonl`);return Kt(a)}function Pe(r,e){let t=e[0]?.id;return r.map((s,n)=>{let o=n===0?null:e[n+1];return{...s,displayEpoch:o?o.created_at_epoch:s.created_at_epoch,displayTime:o?o.created_at:s.created_at,shouldShowLink:s.id!==t}})}function _e(r,e){let t=[...r.map(s=>({type:"observation",data:s})),...e.map(s=>({type:"summary",data:s}))];return t.sort((s,n)=>{let o=s.type==="observation"?s.data.created_at_epoch:s.data.displayEpoch,i=n.type==="observation"?n.data.created_at_epoch:n.data.displayEpoch;return o-i}),t}function je(r,e){return new Set(r.slice(0,e).map(t=>t.id))}function Xe(){let r=new Date,e=r.toLocaleDateString("en-CA"),t=r.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}).toLowerCase().replace(" ",""),s=r.toLocaleTimeString("en-US",{timeZoneName:"short"}).split(" ").pop();return`${e} ${t} ${s}`}function He(r){return[`# [${r}] recent context, ${Xe()}`,""]}function Ge(){return[`Legend: \u{1F3AF}session ${A.getInstance().getActiveMode().observation_types.map(t=>`${t.emoji}${t.id}`).join(" ")}`,"Format: ID TIME TYPE TITLE","Fetch details: get_observations([IDs]) | Search: mem-search skill",""]}function Be(){return[]}function We(){return[]}function qe(r,e){let t=[],s=[`${r.totalObservations} obs (${r.totalReadTokens.toLocaleString()}t read)`,`${r.totalDiscoveryTokens.toLocaleString()}t work`];return r.totalDiscoveryTokens>0&&(e.showSavingsAmount||e.showSavingsPercent)&&(e.showSavingsPercent?s.push(`${r.savingsPercent}% savings`):e.showSavingsAmount&&s.push(`${r.savings.toLocaleString()}t saved`)),t.push(`Stats: ${s.join(" | ")}`),t.push(""),t}function Ve(r){return[`### ${r}`]}function Ye(r){return r.toLowerCase().replace(" am","a").replace(" pm","p")}function Ke(r,e,t){let s=r.title||"Untitled",n=A.getInstance().getTypeIcon(r.type),o=e?Ye(e):'"';return`${r.id} ${o} ${n} ${s}`}function Je(r,e,t,s){let n=[],o=r.title||"Untitled",i=A.getInstance().getTypeIcon(r.type),a=e?Ye(e):'"',{readTokens:d,discoveryDisplay:m}=k(r,s);n.push(`**${r.id}** ${a} ${i} **${o}**`),t&&n.push(t);let u=[];return s.showReadTokens&&u.push(`~${d}t`),s.showWorkTokens&&u.push(m),u.length>0&&n.push(u.join(" ")),n.push(""),n}function Qe(r,e){return[`S${r.id} ${r.request||"Session started"} (${e})`]}function w(r,e){return e?[`**${r}**: ${e}`,""]:[]}function ze(r){return r.assistantMessage?["","---","","**Previously**","",`A: ${r.assistantMessage}`,""]:[]}function Ze(r,e){return["",`Access ${Math.round(r/1e3)}k tokens of past work via get_observations([IDs]) or mem-search skill.`]}function et(r){return`# [${r}] recent context, ${Xe()}
|
||||
|
||||
No previous sessions found.`}function tt(){let r=new Date,e=r.toLocaleDateString("en-CA"),t=r.toLocaleTimeString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0}).toLowerCase().replace(" ",""),s=r.toLocaleTimeString("en-US",{timeZoneName:"short"}).split(" ").pop();return`${e} ${t} ${s}`}function st(r){return["",`${c.bright}${c.cyan}[${r}] recent context, ${tt()}${c.reset}`,`${c.gray}${"\u2500".repeat(60)}${c.reset}`,""]}function rt(){let e=A.getInstance().getActiveMode().observation_types.map(t=>`${t.emoji} ${t.id}`).join(" | ");return[`${c.dim}Legend: session-request | ${e}${c.reset}`,""]}function nt(){return[`${c.bright}Column Key${c.reset}`,`${c.dim} Read: Tokens to read this observation (cost to learn it now)${c.reset}`,`${c.dim} Work: Tokens spent on work that produced this record ( research, building, deciding)${c.reset}`,""]}function ot(){return[`${c.dim}Context Index: This semantic index (titles, types, files, tokens) is usually sufficient to understand past work.${c.reset}`,"",`${c.dim}When you need implementation details, rationale, or debugging context:${c.reset}`,`${c.dim} - Fetch by ID: get_observations([IDs]) for observations visible in this index${c.reset}`,`${c.dim} - Search history: Use the mem-search skill for past decisions, bugs, and deeper research${c.reset}`,`${c.dim} - Trust this index over re-reading code for past decisions and learnings${c.reset}`,""]}function it(r,e){let t=[];if(t.push(`${c.bright}${c.cyan}Context Economics${c.reset}`),t.push(`${c.dim} Loading: ${r.totalObservations} observations (${r.totalReadTokens.toLocaleString()} tokens to read)${c.reset}`),t.push(`${c.dim} Work investment: ${r.totalDiscoveryTokens.toLocaleString()} tokens spent on research, building, and decisions${c.reset}`),r.totalDiscoveryTokens>0&&(e.showSavingsAmount||e.showSavingsPercent)){let s=" Your savings: ";e.showSavingsAmount&&e.showSavingsPercent?s+=`${r.savings.toLocaleString()} tokens (${r.savingsPercent}% reduction from reuse)`:e.showSavingsAmount?s+=`${r.savings.toLocaleString()} tokens`:s+=`${r.savingsPercent}% reduction from reuse`,t.push(`${c.green}${s}${c.reset}`)}return t.push(""),t}function at(r){return[`${c.bright}${c.cyan}${r}${c.reset}`,""]}function dt(r){return[`${c.dim}${r}${c.reset}`]}function ct(r,e,t,s){let n=r.title||"Untitled",o=A.getInstance().getTypeIcon(r.type),{readTokens:i,discoveryTokens:a,workEmoji:d}=k(r,s),m=t?`${c.dim}${e}${c.reset}`:" ".repeat(e.length),u=s.showReadTokens&&i>0?`${c.dim}(~${i}t)${c.reset}`:"",E=s.showWorkTokens&&a>0?`${c.dim}(${d} ${a.toLocaleString()}t)${c.reset}`:"";return` ${c.dim}#${r.id}${c.reset} ${m} ${o} ${n} ${u} ${E}`}function ut(r,e,t,s,n){let o=[],i=r.title||"Untitled",a=A.getInstance().getTypeIcon(r.type),{readTokens:d,discoveryTokens:m,workEmoji:u}=k(r,n),E=t?`${c.dim}${e}${c.reset}`:" ".repeat(e.length),g=n.showReadTokens&&d>0?`${c.dim}(~${d}t)${c.reset}`:"",T=n.showWorkTokens&&m>0?`${c.dim}(${u} ${m.toLocaleString()}t)${c.reset}`:"";return o.push(` ${c.dim}#${r.id}${c.reset} ${E} ${a} ${c.bright}${i}${c.reset}`),s&&o.push(` ${c.dim}${s}${c.reset}`),(g||T)&&o.push(` ${g} ${T}`),o.push(""),o}function mt(r,e){let t=`${r.request||"Session started"} (${e})`;return[`${c.yellow}#S${r.id}${c.reset} ${t}`,""]}function $(r,e,t){return e?[`${t}${r}:${c.reset} ${e}`,""]:[]}function _t(r){return r.assistantMessage?["","---","",`${c.bright}${c.magenta}Previously${c.reset}`,"",`${c.dim}A: ${r.assistantMessage}${c.reset}`,""]:[]}function pt(r,e){let t=Math.round(r/1e3);return["",`${c.dim}Access ${t}k tokens of past research & decisions for just ${e.toLocaleString()}t. Use the claude-mem skill to access memories by ID.${c.reset}`]}function lt(r){return`
|
||||
${c.bright}${c.cyan}[${r}] recent context, ${tt()}${c.reset}
|
||||
@@ -760,5 +760,5 @@ ${c.gray}${"\u2500".repeat(60)}${c.reset}
|
||||
|
||||
${c.dim}No previous sessions found for this project yet.${c.reset}
|
||||
`}function Et(r,e,t,s){let n=[];return s?n.push(...st(r)):n.push(...He(r)),s?n.push(...rt()):n.push(...Ge()),s?n.push(...nt()):n.push(...Be()),s?n.push(...ot()):n.push(...We()),V(t)&&(s?n.push(...it(e,t)):n.push(...qe(e,t))),n}var pe=L(require("path"),1);function Q(r){if(!r)return[];try{let e=JSON.parse(r);return Array.isArray(e)?e:[]}catch(e){return _.debug("PARSER","Failed to parse JSON array, using empty fallback",{preview:r?.substring(0,50)},e instanceof Error?e:new Error(String(e))),[]}}function le(r){return new Date(r).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit",hour12:!0})}function Ee(r){return new Date(r).toLocaleString("en-US",{hour:"numeric",minute:"2-digit",hour12:!0})}function Tt(r){return new Date(r).toLocaleString("en-US",{month:"short",day:"numeric",year:"numeric"})}function gt(r,e){return pe.default.isAbsolute(r)?pe.default.relative(e,r):r}function ft(r,e,t){let s=Q(r);if(s.length>0)return gt(s[0],e);if(t){let n=Q(t);if(n.length>0)return gt(n[0],e)}return"General"}function Jt(r){let e=new Map;for(let s of r){let n=s.type==="observation"?s.data.created_at:s.data.displayTime,o=Tt(n);e.has(o)||e.set(o,[]),e.get(o).push(s)}let t=Array.from(e.entries()).sort((s,n)=>{let o=new Date(s[0]).getTime(),i=new Date(n[0]).getTime();return o-i});return new Map(t)}function St(r,e){return e.fullObservationField==="narrative"?r.narrative:r.facts?Q(r.facts).join(`
|
||||
`):null}function Qt(r,e,t,s){let n=[];n.push(...Ve(r));let o="";for(let i of e)if(i.type==="summary"){let a=i.data,d=le(a.displayTime);n.push(...Qe(a,d))}else{let a=i.data,d=Ee(a.created_at),u=d!==o?d:"";if(o=d,t.has(a.id)){let g=St(a,s);n.push(...Je(a,u,g,s))}else n.push(Ke(a,u,s))}return n}function zt(r,e,t,s,n){let o=[];o.push(...at(r));let i=null,a="";for(let d of e)if(d.type==="summary"){i=null,a="";let m=d.data,u=le(m.displayTime);o.push(...mt(m,u))}else{let m=d.data,u=ft(m.files_modified,n,m.files_read),E=Ee(m.created_at),g=E!==a;a=E;let T=t.has(m.id);if(u!==i&&(o.push(...dt(u)),i=u),T){let O=St(m,s);o.push(...ut(m,E,g,O,s))}else o.push(ct(m,E,g,s))}return o.push(""),o}function Zt(r,e,t,s,n,o){return o?zt(r,e,t,s,n):Qt(r,e,t,s)}function bt(r,e,t,s,n){let o=[],i=Jt(r);for(let[a,d]of i)o.push(...Zt(a,d,e,t,s,n));return o}function ht(r,e,t){return!(!r.showLastSummary||!e||!!!(e.investigated||e.learned||e.completed||e.next_steps)||t&&e.created_at_epoch<=t.created_at_epoch)}function Ot(r,e){let t=[];return e?(t.push(...$("Investigated",r.investigated,c.blue)),t.push(...$("Learned",r.learned,c.yellow)),t.push(...$("Completed",r.completed,c.green)),t.push(...$("Next Steps",r.next_steps,c.magenta))):(t.push(...w("Investigated",r.investigated)),t.push(...w("Learned",r.learned)),t.push(...w("Completed",r.completed)),t.push(...w("Next Steps",r.next_steps))),t}function At(r,e){return e?_t(r):ze(r)}function Rt(r,e,t){return!V(e)||r.totalDiscoveryTokens<=0||r.savings<=0?[]:t?pt(r.totalDiscoveryTokens,r.totalReadTokens):Ze(r.totalDiscoveryTokens,r.totalReadTokens)}var es=Nt.default.join((0,Ct.homedir)(),".claude","plugins","marketplaces","thedotmack","plugin",".install-version");function ts(){try{return new B}catch(r){if(r instanceof Error&&r.code==="ERR_DLOPEN_FAILED"){try{(0,It.unlinkSync)(es)}catch(e){e instanceof Error?_.debug("WORKER","Marker file cleanup failed (may not exist)",{},e):_.debug("WORKER","Marker file cleanup failed (may not exist)",{error:String(e)})}return _.error("WORKER","Native module rebuild needed - restart Claude Code to auto-fix"),null}throw r}}function ss(r,e){return e?lt(r):et(r)}function rs(r,e,t,s,n,o,i){let a=[],d=de(e);a.push(...Et(r,d,s,i));let m=t.slice(0,s.sessionCount),u=Pe(m,t),E=_e(e,u),g=Xe(e,s.fullObservationCount);a.push(...bt(E,g,s,n,i));let T=t[0],O=e[0];ht(s,T,O)&&a.push(...Ot(T,i));let S=me(e,s,o,n);return a.push(...At(S,i)),a.push(...Rt(d,s,i)),a.join(`
|
||||
`):null}function Qt(r,e,t,s){let n=[];n.push(...Ve(r));let o="";for(let i of e)if(i.type==="summary"){let a=i.data,d=le(a.displayTime);n.push(...Qe(a,d))}else{let a=i.data,d=Ee(a.created_at),u=d!==o?d:"";if(o=d,t.has(a.id)){let g=St(a,s);n.push(...Je(a,u,g,s))}else n.push(Ke(a,u,s))}return n}function zt(r,e,t,s,n){let o=[];o.push(...at(r));let i=null,a="";for(let d of e)if(d.type==="summary"){i=null,a="";let m=d.data,u=le(m.displayTime);o.push(...mt(m,u))}else{let m=d.data,u=ft(m.files_modified,n,m.files_read),E=Ee(m.created_at),g=E!==a;a=E;let T=t.has(m.id);if(u!==i&&(o.push(...dt(u)),i=u),T){let O=St(m,s);o.push(...ut(m,E,g,O,s))}else o.push(ct(m,E,g,s))}return o.push(""),o}function Zt(r,e,t,s,n,o){return o?zt(r,e,t,s,n):Qt(r,e,t,s)}function bt(r,e,t,s,n){let o=[],i=Jt(r);for(let[a,d]of i)o.push(...Zt(a,d,e,t,s,n));return o}function ht(r,e,t){return!(!r.showLastSummary||!e||!!!(e.investigated||e.learned||e.completed||e.next_steps)||t&&e.created_at_epoch<=t.created_at_epoch)}function Ot(r,e){let t=[];return e?(t.push(...$("Investigated",r.investigated,c.blue)),t.push(...$("Learned",r.learned,c.yellow)),t.push(...$("Completed",r.completed,c.green)),t.push(...$("Next Steps",r.next_steps,c.magenta))):(t.push(...w("Investigated",r.investigated)),t.push(...w("Learned",r.learned)),t.push(...w("Completed",r.completed)),t.push(...w("Next Steps",r.next_steps))),t}function At(r,e){return e?_t(r):ze(r)}function Rt(r,e,t){return!V(e)||r.totalDiscoveryTokens<=0||r.savings<=0?[]:t?pt(r.totalDiscoveryTokens,r.totalReadTokens):Ze(r.totalDiscoveryTokens,r.totalReadTokens)}var es=Nt.default.join((0,Ct.homedir)(),".claude","plugins","marketplaces","thedotmack","plugin",".install-version");function ts(){try{return new B}catch(r){if(r instanceof Error&&r.code==="ERR_DLOPEN_FAILED"){try{(0,It.unlinkSync)(es)}catch(e){e instanceof Error?_.debug("WORKER","Marker file cleanup failed (may not exist)",{},e):_.debug("WORKER","Marker file cleanup failed (may not exist)",{error:String(e)})}return _.error("WORKER","Native module rebuild needed - restart Claude Code to auto-fix"),null}throw r}}function ss(r,e){return e?lt(r):et(r)}function rs(r,e,t,s,n,o,i){let a=[],d=de(e);a.push(...Et(r,d,s,i));let m=t.slice(0,s.sessionCount),u=Pe(m,t),E=_e(e,u),g=je(e,s.fullObservationCount);a.push(...bt(E,g,s,n,i));let T=t[0],O=e[0];ht(s,T,O)&&a.push(...Ot(T,i));let S=me(e,s,o,n);return a.push(...At(S,i)),a.push(...Rt(d,s,i)),a.join(`
|
||||
`).trimEnd()}async function ge(r,e=!1){let t=oe(),s=r?.cwd??process.cwd(),n=se(s),o=r?.platform_source,i=r?.projects?.length?r.projects:n.allProjects,a=i[i.length-1]??n.primary;r?.full&&(t.totalObservationCount=999999,t.sessionCount=999999);let d=ts();if(!d)return"";try{let m=i.length>1?$e(d,i,t,o):ce(d,a,t,o),u=i.length>1?Fe(d,i,t,o):ue(d,a,t,o);return m.length===0&&u.length===0?ss(a,e):rs(a,m,u,t,s,r?.session_id,e)}finally{d.close()}}0&&(module.exports={generateContext});
|
||||
|
||||
File diff suppressed because one or more lines are too long
+225
-202
File diff suppressed because one or more lines are too long
+11
-11
File diff suppressed because one or more lines are too long
@@ -33,10 +33,15 @@ export class SessionSearch {
|
||||
this.db = new Database(dbPath);
|
||||
this.db.run('PRAGMA journal_mode = WAL');
|
||||
|
||||
// Cache FTS5 availability once at construction (avoids DDL probe on every query)
|
||||
this._fts5Available = this.isFts5Available();
|
||||
|
||||
// Ensure FTS tables exist
|
||||
this.ensureFTSTables();
|
||||
}
|
||||
|
||||
private _fts5Available: boolean;
|
||||
|
||||
/**
|
||||
* Ensure FTS5 tables exist (backward compatibility only - no longer used for search)
|
||||
*
|
||||
@@ -307,9 +312,33 @@ export class SessionSearch {
|
||||
return this.db.prepare(sql).all(...params) as ObservationSearchResult[];
|
||||
}
|
||||
|
||||
// Vector search with query text should be handled by ChromaDB
|
||||
// This method only supports filter-only queries (query=undefined)
|
||||
logger.warn('DB', 'Text search not supported - use ChromaDB for vector search');
|
||||
// FTS5 keyword fallback when ChromaDB is unavailable (#1913, #2048)
|
||||
if (this._fts5Available) {
|
||||
const filterClause = this.buildFilterClause(filters, params, 'o');
|
||||
const orderClause = this.buildOrderClause(orderBy, true, 'observations_fts');
|
||||
|
||||
const sql = `
|
||||
SELECT o.*, o.discovery_tokens
|
||||
FROM observations o
|
||||
JOIN observations_fts ON observations_fts.rowid = o.id
|
||||
WHERE observations_fts MATCH ?
|
||||
${filterClause ? 'AND ' + filterClause : ''}
|
||||
${orderClause}
|
||||
LIMIT ? OFFSET ?
|
||||
`;
|
||||
|
||||
params.unshift(query);
|
||||
params.push(limit, offset);
|
||||
|
||||
try {
|
||||
return this.db.prepare(sql).all(...params) as ObservationSearchResult[];
|
||||
} catch (error) {
|
||||
logger.warn('DB', 'FTS5 observation search failed, returning empty', {}, error instanceof Error ? error : undefined);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
logger.warn('DB', 'Text search unavailable: ChromaDB disabled and FTS5 not available');
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -346,9 +375,38 @@ export class SessionSearch {
|
||||
return this.db.prepare(sql).all(...params) as SessionSummarySearchResult[];
|
||||
}
|
||||
|
||||
// Vector search with query text should be handled by ChromaDB
|
||||
// This method only supports filter-only queries (query=undefined)
|
||||
logger.warn('DB', 'Text search not supported - use ChromaDB for vector search');
|
||||
// FTS5 keyword fallback when ChromaDB is unavailable (#1913, #2048)
|
||||
if (this._fts5Available) {
|
||||
const filterOptions = { ...filters };
|
||||
delete filterOptions.type;
|
||||
const filterClause = this.buildFilterClause(filterOptions, params, 's');
|
||||
|
||||
const orderClause = orderBy === 'date_asc'
|
||||
? 'ORDER BY s.created_at_epoch ASC'
|
||||
: 'ORDER BY session_summaries_fts.rank ASC';
|
||||
|
||||
const sql = `
|
||||
SELECT s.*, s.discovery_tokens
|
||||
FROM session_summaries s
|
||||
JOIN session_summaries_fts ON session_summaries_fts.rowid = s.id
|
||||
WHERE session_summaries_fts MATCH ?
|
||||
${filterClause ? 'AND ' + filterClause : ''}
|
||||
${orderClause}
|
||||
LIMIT ? OFFSET ?
|
||||
`;
|
||||
|
||||
params.unshift(query);
|
||||
params.push(limit, offset);
|
||||
|
||||
try {
|
||||
return this.db.prepare(sql).all(...params) as SessionSummarySearchResult[];
|
||||
} catch (error) {
|
||||
logger.warn('DB', 'FTS5 session search failed, returning empty', {}, error instanceof Error ? error : undefined);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
logger.warn('DB', 'Text search unavailable: ChromaDB disabled and FTS5 not available');
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -586,10 +644,26 @@ export class SessionSearch {
|
||||
return this.db.prepare(sql).all(...params) as UserPromptSearchResult[];
|
||||
}
|
||||
|
||||
// Vector search with query text should be handled by ChromaDB
|
||||
// This method only supports filter-only queries (query=undefined)
|
||||
logger.warn('DB', 'Text search not supported - use ChromaDB for vector search');
|
||||
return [];
|
||||
// LIKE fallback for user prompts text search (no FTS table for this entity)
|
||||
baseConditions.push('up.prompt_text LIKE ?');
|
||||
params.push(`%${query}%`);
|
||||
|
||||
const whereClause = `WHERE ${baseConditions.join(' AND ')}`;
|
||||
const orderClause = orderBy === 'date_asc'
|
||||
? 'ORDER BY up.created_at_epoch ASC'
|
||||
: 'ORDER BY up.created_at_epoch DESC';
|
||||
|
||||
const sql = `
|
||||
SELECT up.*
|
||||
FROM user_prompts up
|
||||
JOIN sdk_sessions s ON up.content_session_id = s.content_session_id
|
||||
${whereClause}
|
||||
${orderClause}
|
||||
LIMIT ? OFFSET ?
|
||||
`;
|
||||
|
||||
params.push(limit, offset);
|
||||
return this.db.prepare(sql).all(...params) as UserPromptSearchResult[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -44,6 +44,7 @@ export class SessionStore {
|
||||
this.db.run('PRAGMA journal_mode = WAL');
|
||||
this.db.run('PRAGMA synchronous = NORMAL');
|
||||
this.db.run('PRAGMA foreign_keys = ON');
|
||||
this.db.run('PRAGMA journal_size_limit = 4194304'); // 4MB WAL cap (#1956)
|
||||
|
||||
// Initialize schema if needed (fresh database)
|
||||
this.initializeSchema();
|
||||
|
||||
@@ -557,6 +557,32 @@ export class WorkerService {
|
||||
logger.error('WORKER', 'Stale session reaper error with non-Error', {}, new Error(String(e)));
|
||||
}
|
||||
}
|
||||
|
||||
// Purge failed pending messages to prevent unbounded queue growth (#1957)
|
||||
try {
|
||||
const pendingStore = this.sessionManager.getPendingMessageStore();
|
||||
const purged = pendingStore.clearFailed();
|
||||
if (purged > 0) {
|
||||
logger.info('SYSTEM', `Purged ${purged} failed pending messages`);
|
||||
}
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
logger.error('WORKER', 'Failed message purge error', {}, e);
|
||||
} else {
|
||||
logger.error('WORKER', 'Failed message purge error with non-Error', {}, new Error(String(e)));
|
||||
}
|
||||
}
|
||||
|
||||
// Periodic WAL checkpoint to prevent unbounded WAL growth (#1956)
|
||||
try {
|
||||
this.dbManager.getSessionStore().db.run('PRAGMA wal_checkpoint(PASSIVE)');
|
||||
} catch (e) {
|
||||
if (e instanceof Error) {
|
||||
logger.error('WORKER', 'WAL checkpoint error', {}, e);
|
||||
} else {
|
||||
logger.error('WORKER', 'WAL checkpoint error with non-Error', {}, new Error(String(e)));
|
||||
}
|
||||
}
|
||||
}, 2 * 60 * 1000);
|
||||
|
||||
// Auto-recover orphaned queues (fire-and-forget with error logging)
|
||||
|
||||
@@ -97,6 +97,12 @@ export class SearchManager {
|
||||
delete normalized.filePath;
|
||||
}
|
||||
|
||||
// Map concept (singular, HTTP query param) to concepts (plural, internal key)
|
||||
if (normalized.concept && !normalized.concepts) {
|
||||
normalized.concepts = normalized.concept;
|
||||
delete normalized.concept;
|
||||
}
|
||||
|
||||
// Parse comma-separated concepts into array
|
||||
if (normalized.concepts && typeof normalized.concepts === 'string') {
|
||||
normalized.concepts = normalized.concepts.split(',').map((s: string) => s.trim()).filter(Boolean);
|
||||
@@ -277,14 +283,18 @@ export class SearchManager {
|
||||
logger.debug('SEARCH', 'ChromaDB found no matches (final result, no FTS5 fallback)', {});
|
||||
}
|
||||
}
|
||||
// ChromaDB not initialized - mark as failed to show proper error message
|
||||
// ChromaDB not initialized - fall back to FTS5 keyword search (#1913, #2048)
|
||||
else if (query) {
|
||||
chromaFailed = true;
|
||||
logger.debug('SEARCH', 'ChromaDB not initialized - semantic search unavailable', {});
|
||||
logger.debug('SEARCH', 'Install UVX/Python to enable vector search', { url: 'https://docs.astral.sh/uv/getting-started/installation/' });
|
||||
observations = [];
|
||||
sessions = [];
|
||||
prompts = [];
|
||||
logger.debug('SEARCH', 'ChromaDB not initialized — falling back to FTS5 keyword search', {});
|
||||
if (searchObservations) {
|
||||
observations = this.sessionSearch.searchObservations(query, { ...options, type: obs_type, concepts, files });
|
||||
}
|
||||
if (searchSessions) {
|
||||
sessions = this.sessionSearch.searchSessions(query, options);
|
||||
}
|
||||
if (searchPrompts) {
|
||||
prompts = this.sessionSearch.searchUserPrompts(query, options);
|
||||
}
|
||||
}
|
||||
|
||||
const totalResults = observations.length + sessions.length + prompts.length;
|
||||
|
||||
@@ -80,17 +80,31 @@ export async function processAgentResponse(
|
||||
|
||||
const summary = parseSummary(text, session.sessionDbId, summaryExpected);
|
||||
|
||||
if (
|
||||
// Detect non-XML responses (auth errors, rate limits, garbled output).
|
||||
// When the response contains no parseable XML and produced no observations,
|
||||
// mark the pending messages as failed instead of confirming them — this prevents
|
||||
// silent data loss when the LLM returns garbage (#1874).
|
||||
const isNonXmlResponse = (
|
||||
text.trim() &&
|
||||
observations.length === 0 &&
|
||||
!summary &&
|
||||
!/<observation>|<summary>|<skip_summary\b/.test(text)
|
||||
) {
|
||||
);
|
||||
|
||||
if (isNonXmlResponse) {
|
||||
const preview = text.length > 200 ? `${text.slice(0, 200)}...` : text;
|
||||
logger.warn('PARSER', `${agentName} returned non-XML response; observation content was discarded`, {
|
||||
logger.warn('PARSER', `${agentName} returned non-XML response; marking messages as failed for retry (#1874)`, {
|
||||
sessionId: session.sessionDbId,
|
||||
preview
|
||||
});
|
||||
|
||||
// Mark messages as failed (retry logic in PendingMessageStore handles retries)
|
||||
const pendingStore = sessionManager.getPendingMessageStore();
|
||||
for (const messageId of session.processingMessageIds) {
|
||||
pendingStore.markFailed(messageId);
|
||||
}
|
||||
session.processingMessageIds = [];
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert nullable fields to empty strings for storeSummary (if summary exists)
|
||||
|
||||
@@ -38,7 +38,14 @@ export class ViewerRoutes extends BaseRouteHandler {
|
||||
* Health check endpoint
|
||||
*/
|
||||
private handleHealth = this.wrapHandler((req: Request, res: Response): void => {
|
||||
res.json({ status: 'ok', timestamp: Date.now() });
|
||||
// Include queue liveness info so monitoring can detect dead queues (#1867)
|
||||
const activeSessions = this.sessionManager.getActiveSessionCount();
|
||||
|
||||
res.json({
|
||||
status: 'ok',
|
||||
timestamp: Date.now(),
|
||||
activeSessions
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user