feat(memory): memory_pending lists earlier-session milestones

This commit is contained in:
bchanot committed 2026-11-05 16:59:25 +01:00
1 parent 66696e9a3e
commit 78eff1cf34
2 files changed
+86 -13

No files matched your search

+47 -2
View File
@@ -785,7 +785,7 @@ test('milestones, sub-agent, earlier session and order', async ($, on) => {
expect(await pending($)).toBe([
'memory_pending (project app, 2 session(s))',
'index: read blockers.md, learnings.md',
'milestones (this session):',
'milestones:',
'- commit fix: x (' + localHhmm(3600000 * 14 + 120000) + ')',
'failures:',
'- NEW \u00d72 (sub-agent) brand new line here ok \u2014 command: c',
@@ -799,6 +799,39 @@ test('milestones, sub-agent, earlier session and order', async ($, on) => {
].join('\n'))
})
test('PM1: current milestone first, then the earlier one', async (
$, on,
) => {
const mk = (id: string, at: number, ms: unknown[]) =>
({ id, at, failures: [], milestones: ms, red: [] })
const seed = { [`p:${ROOT}`]: { sessions: [
mk('s0', 100, [{ kind: 'commit', label: 'fix: old', at: 7200000 }]),
mk('s1', 900, [{ kind: 'commit', label: 'fix: new', at: 3600000 }]),
] } }
await boot($, on, { seed })
expect(await pending($)).toBe([
'memory_pending (project app, 2 session(s))',
'index: skipped blockers.md (missing), learnings.md (missing)',
'milestones:',
'- commit fix: new (' + localHhmm(3600000) + ')',
'- commit fix: old (' + localHhmm(7200000) + ') (earlier session)',
].join('\n'))
})
test('PM2: only an earlier milestone is not nothing captured', async (
$, on,
) => {
const seed = { [`p:${ROOT}`]: { sessions: [
{ id: 's0', at: 100, failures: [], red: [],
milestones: [{ kind: 'commit', label: 'fix: probe', at: 3600000 }] },
] } }
await boot($, on, { seed })
const text = await pending($)
expect(text).not.toBe('memory_pending: nothing captured')
expect(text).toContain(
'- commit fix: probe (' + localHhmm(3600000) + ') (earlier session)')
})
test('the excerpt shows its last 300 characters', async ($, on) => {
const w = await boot($, on)
await failing($, w, EXIT1 + 'x'.repeat(400) + '\nfatal: tail marker')
@@ -1143,7 +1176,7 @@ test('a stored commit milestone shows in the memory_pending answer', async (
expect(await pending($)).toBe([
'memory_pending (project app, 1 session(s))',
'index: skipped blockers.md (missing), learnings.md (missing)',
'milestones (this session):',
'milestones:',
'- commit fix(x): y (' + localHhmm(1000) + ')',
].join('\n'))
})
@@ -2627,6 +2660,17 @@ test('TE4: the same failure 20 times in one context injects once',
expect(injected).toBe(1)
})
test('TE7: the status reader runs only for a candidate', async (
$, on,
) => {
const w = await bootKnown($, on)
const known = w.runs.length
await failing($, w, EXIT1 + 'fatal: nothing alike zebra quartz')
expect(w.runs.length).toBe(known)
await failing($, w, EXIT1 + KN_SPAN)
expect(w.runs.length - known).toBe(1)
})
test('TE4b: two concurrent failing calls inject one line', async (
$, on,
) => {
@@ -2760,4 +2804,5 @@ test('PC2: a throwing recall still lets the note attach', async ($, on) => {
origin: { kind: 'composer' } })
expect(added).toHaveLength(1)
expect(added[0]).toContain('memory: commit fix: y')
expect(w.logs.filter(l => l.includes('prompt.submit'))).toEqual([])
})
+39 -11
View File
@@ -852,11 +852,22 @@ function failureText({ f, id, earlier }: Row): string {
return `${head}\n excerpt: ${shown}`
}
function milestoneText(m: Milestone): string {
function milestoneText(m: Milestone, earlier = false): string {
const d = new Date(m.at)
const two = (n: number) => String(n).padStart(2, '0')
const hhmm = `${two(d.getHours())}:${two(d.getMinutes())}`
return `- ${m.kind} ${m.label} (${hhmm})`
const mark = earlier ? ' (earlier session)' : ''
return `- ${m.kind} ${m.label} (${hhmm})${mark}`
}
/** Current session first, then the earlier ones, newest session first. */
function milestoneLines(p: Project, curId: string): string[] {
const lines = (s: Session) => s.milestones.filter(isMilestone)
.map(m => milestoneText(m, s.id !== curId))
const cur = p.sessions.filter(s => s.id === curId)
const old = p.sessions.filter(s => s.id !== curId)
.sort((a, b) => b.at - a.at)
return [...cur, ...old].flatMap(lines)
}
/** The failure list within ANSWER_CAP; the rest is counted, not shown. */
@@ -879,14 +890,13 @@ export function formatPending(
rx: Registries,
): string {
const rows = rowsOf(p, curId, rx.index)
const cur = p.sessions.find(s => s.id === curId)
const ms = (cur?.milestones ?? []).filter(isMilestone)
const ms = milestoneLines(p, curId)
if (rows.length === 0 && ms.length === 0) return NOTHING_TEXT
const name = root.split('/').filter(Boolean).pop() ?? root
const out = [`memory_pending (project ${name}, ${p.sessions.length} ` +
'session(s))', rx.note]
if (ms.length > 0) {
out.push('milestones (this session):', ...ms.map(milestoneText))
out.push('milestones:', ...ms)
}
if (rows.length > 0) {
out.push('failures:', ...capFailures(rows.map(failureText)))
@@ -1390,10 +1400,30 @@ async function captureMilestones(
}
}
/**
* The live BLK or LRN entry `key` matches. The match runs on every entry
* first: the status reader is spawned only for a candidate ID.
*/
async function liveCandidate(
$: Api,
root: string,
key: string,
): Promise<Entry | undefined> {
const { texts } = await readRegistries($, root, FAILURE_FILES)
const all = assembleEntries(texts, new Map())
const failing = all.filter(e => FAILURE_KINDS.has(e.kind))
const id = matchOf(buildIndex(failing, undefined), key)
if (id === undefined) return undefined
const status = await statusMap($, root)
if (status === undefined || !isLive(status, id)) return undefined
return assembleEntries(texts, status).find(e => e.id === id)
}
/**
* The known-error line of a failure: `memory: known <entry>` when a live
* BLK or LRN matches and the context has not seen it nor spent its budget.
* '' otherwise. Claims after the last await.
* '' otherwise. Claims synchronously once the reads are done; only the
* log write follows.
*/
async function knownLine(
$: Api,
@@ -1403,15 +1433,13 @@ async function knownLine(
agent: string | undefined,
): Promise<string> {
if (!(await ensureRecall($, st))) return ''
const rx = await loadRegistries($, at.root, FAILURE_FILES)
if (rx.status === undefined) return ''
const id = matchOf(rx.index, f.key)
const entry = rx.entries.find(e => e.id === id)
const entry = await liveCandidate($, at.root, f.key)
if (entry === undefined) return ''
const line = `memory: known ${recallLine(entry)}`
const key = contextKey(at.id, agent)
const now = await $.clock.now()
if (claim(st, key, [entry.id], [line.length]).length === 0) return ''
const record = { at: await $.clock.now(), session: at.id, ids: [entry.id] }
const record = { at: now, session: at.id, ids: [entry.id] }
await appendLog($, st, at.root, {
...record, agent: agent ?? 'main', channel: 'tool',
}).catch(() => undefined)