fix(builtin): session lifecycle + frontmatter preamble stripping #441

Merged
xiaomo merged 2 commits from fix/builtin-session-lifecycle into main 2026-05-23 13:20:05 +00:00
Owner

What

Fix two bugs found during dogfooding the builtin agent:

  1. Session JSONL deleted too earlyremoveSession was called at the end of every runBuiltinWithMessages, wiping the session file before continue could use it
  2. LLM preamble before frontmatter — LLM sometimes emits text before the --- fence, causing parse failure

Changes

Bug 1: Session lifecycle

  • Removed removeSession call from runBuiltinWithMessages — session files now persist naturally
  • Session JSONL is harmless after detail is stored to CAS (redundant but useful for debugging)

Bug 2: Frontmatter preamble

  • Added stripPreamble() in agent.ts — defensively strips text before the first --- fence
  • Strengthened system prompt with CRITICAL instruction that output must start with --- at position 0

Testing

  • All 10 builtin tests pass
  • Dogfood run confirmed: session JSONL accumulates across turns, LLM output with preamble is now handled

Ref: dogfood thread 06F59MSH1JJ9PPYM49893FW9H8

## What Fix two bugs found during dogfooding the builtin agent: 1. **Session JSONL deleted too early** — `removeSession` was called at the end of every `runBuiltinWithMessages`, wiping the session file before `continue` could use it 2. **LLM preamble before frontmatter** — LLM sometimes emits text before the `---` fence, causing parse failure ## Changes ### Bug 1: Session lifecycle - Removed `removeSession` call from `runBuiltinWithMessages` — session files now persist naturally - Session JSONL is harmless after detail is stored to CAS (redundant but useful for debugging) ### Bug 2: Frontmatter preamble - Added `stripPreamble()` in `agent.ts` — defensively strips text before the first `---` fence - Strengthened system prompt with CRITICAL instruction that output must start with `---` at position 0 ## Testing - All 10 builtin tests pass - Dogfood run confirmed: session JSONL accumulates across turns, LLM output with preamble is now handled Ref: dogfood thread 06F59MSH1JJ9PPYM49893FW9H8
xingyue added 2 commits 2026-05-23 12:37:59 +00:00
Previously runBuiltinWithMessages deleted the session jsonl after each
run/continue call. This meant the createAgent retry mechanism (which
calls continue on frontmatter validation failure) would lose all
previous turn data — each continue started with an empty jsonl.

Now the session jsonl accumulates across run + continue calls, so the
final storeBuiltinDetail captures all turns. The jsonl file is left
behind for debugging; it's small and can be cleaned up on next startup.

Also add a workflow hint to the system prompt reminding the LLM to use
tools before outputting frontmatter, preventing premature text-only
responses on the first turn.
- Add stripPreamble() to handle LLM output with text before ---
- Strengthen system prompt: CRITICAL instruction for --- at position 0
- Fixes frontmatter parsing failures on first output turn
xiaomo approved these changes 2026-05-23 13:20:04 +00:00
xiaomo left a comment
Owner

LGTM

Bug 1: removeSession 移除正确,session JSONL 应保留供 continue 使用。
Bug 2: prompt CRITICAL 指令 + stripPreamble 双保险,tagged log 方便追踪。

LGTM ✅ Bug 1: removeSession 移除正确,session JSONL 应保留供 continue 使用。 Bug 2: prompt CRITICAL 指令 + stripPreamble 双保险,tagged log 方便追踪。
xiaomo merged commit f07a6daa30 into main 2026-05-23 13:20:05 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#441