Compare commits

...

1 Commits

Author SHA1 Message Date
xiaoju 32bbea0f32 fix: decouple session resume from isFirstVisit guard
CI / check (pull_request) Successful in 1m58s
When frontmatter validation fails, the step is never written to CAS, so
isFirstVisit remains true on the next run.  Both agent-claude-code and
agent-hermes gated session cache lookup behind !isFirstVisit, which
caused them to start a fresh session (and a new worktree) instead of
resuming the one that already has all the work done.

Remove the isFirstVisit guard from both adapters so they always check
the session cache.  If no cache entry exists, the behavior is unchanged
(fresh session).  If a cache entry exists, the agent resumes the
previous session regardless of CAS step state.

Fixes #139
2026-06-07 01:49:04 +00:00
2 changed files with 11 additions and 3 deletions
@@ -176,8 +176,12 @@ async function runClaudeCode(ctx: AgentContext, model: string | null): Promise<A
log("K7R2M4N8", `prompt for role=${ctx.role} (length=${fullPrompt.length}):\n${fullPrompt}`);
// Try resuming a cached session for re-entry scenarios (e.g. reviewer reject → developer re-entry).
if (!ctx.isFirstVisit) {
// Try resuming a cached session. This covers both normal re-entry
// (e.g. reviewer reject → developer re-entry) AND the case where a
// previous run completed but frontmatter validation failed — the step
// was never written to CAS so isFirstVisit is still true, but the
// session cache holds a valid session we should resume.
{
const cachedSessionId = await getCachedSessionId(
"claude-code",
ctx.threadId,
+5 -1
View File
@@ -110,11 +110,15 @@ async function prepareSession(
cwd: string,
resumeDisabled: boolean,
): Promise<PromptAttempt> {
if (ctx.isFirstVisit || resumeDisabled) {
if (resumeDisabled) {
await client.connect(cwd);
return { useContinuation: false, resumed: false };
}
// Check session cache regardless of isFirstVisit. A previous run may
// have completed and cached its session but failed frontmatter
// validation — the step never got written to CAS so isFirstVisit is
// still true, yet we should resume the existing session.
const cachedSessionId = await getCachedSessionId(ctx.threadId, ctx.role, ctx.storageRoot);
if (cachedSessionId === null) {
log("6RWK3N8Q", `no cached session for ${ctx.threadId}:${ctx.role}, starting new session`);