fix: decouple session resume from isFirstVisit guard #140
Reference in New Issue
Block a user
Delete Branch "fix/139-session-resume-on-frontmatter-fail"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Remove the
isFirstVisitguard from session cache lookup in bothagent-claude-codeandagent-hermes.Why
When frontmatter validation fails, the step is never written to CAS →
isFirstVisitstaystrueon the next run → session cache is skipped → agent starts a fresh session (new worktree) → all previous work is wasted.This burned ~30 min of Claude Code time and 1603 lines of working code on ocas #83 — the agent wrote everything, committed it, but the frontmatter did not parse, so the next run ignored the cached session and started from scratch.
Changes
packages/agent-claude-code/src/claude-code.ts— removeif (!ctx.isFirstVisit)guard around session cache check. Now always checks cache; falls back to fresh session if no cache entry exists.packages/agent-hermes/src/hermes.ts— removectx.isFirstVisit ||from prepareSession guard. Same logic: onlyresumeDisabledcan skip cache lookup.Ref
Fixes #139
32bbea0f32toaaadab4445LGTM ✅
Bug 分析准确: frontmatter 验证失败 → step 不写 CAS → isFirstVisit 永远 true → session cache 被跳过 → 上一轮所有工作白费。30 min + 1603 行代码的教训。
修复逻辑清晰:
isFirstVisit对 session cache lookup 的守卫,改为始终检查 cacheisFirstVisit + cache hit= frontmatter retry,发 minimal prompt 让 agent 只重新输出格式!isFirstVisit + cache hit= 正常 re-entry,走 continuation promptbuildFrontmatterRetryPrompt设计合理:outputFormatInstruction让 agent 知道正确格式hermes 的
PromptAttempt扩展干净: 新增frontmatterRetry字段,useContinuation和frontmatterRetry互斥逻辑正确(isFirstVisit时useContinuation: false, frontmatterRetry: true)。可以合。