#3532·Archon

bug(workflows): loop_group body gate resumes the pre-iteration session after a pause, so fresh_context: false loses the paused iteration

Author: boschetCreated Sep 26, 2026Updated Sep 26, 2026

Problem

A loop_group whose body ends in an approval gate (the "gate as terminal sink" form that #2707 describes as the successor of interactive:) loses the body's session continuity at every pause.

With fresh_context: false, body AI nodes are supposed to continue the session of the previous iteration. That holds as long as the gate does not pause. As soon as the gate pauses and the run is resumed with workflow respond, the next iteration continues the session from before the paused iteration. The turns of the paused iteration are missing from the conversation.

  • If the gate pauses in every iteration, every iteration starts cold (1 turn each).
  • If the gate pauses only sometimes (when: on the gate), the chain skips exactly the paused iterations (observed: iterations 1, 3, 4 instead of 1, 2, 3, 4).

The gate's response itself still arrives correctly via $LOOP_PREV.gate.output.

In terms of the AI node's session (each number is one iteration's turn in the same conversation):

no pause:            1 → 2 → 3 → 4        one continuous session ("warm")
pause after 2:       1 → 2 ⏸ respond
                     1 ──────→ 3 → 4      iteration 2 is gone from the session
pause every time:    1 ⏸   2 ⏸   3 ⏸     each iteration is a new one-turn session ("cold")

"Warm" here means: the node remembers its earlier iterations and their tokens are served from the prompt cache. "Cold" means: the node starts without that history and re-reads its context uncached.

Why

The legacy form (loop_group.interactive: true) keeps the session warm across pauses. The documented successor form does not. So migrating away from the deprecated fields (#2707) currently costs session continuity for any human-in-the-loop loop where the AI node needs to remember earlier iterations (iterative drafting, review rounds). It also makes each iteration re-read its full context uncached.

Desired outcome

After a pause at a body gate and workflow respond, the next iteration's AI nodes continue the session that includes the paused iteration's turns, the same as iterations that did not pause.

Acceptance

  • A loop_group with fresh_context: false and a terminal body gate that pauses every iteration: the AI node's session in iteration N contains the turns of iterations 1..N-1.
  • Same with a conditional gate (when:) that pauses only in some iterations: no iteration is missing from the chain.
  • $LOOP_PREV.gate.output keeps working as today.

Evidence

Reproduction

yaml
name: body-gate-cursor
description: Repro for the upstream issue (body gate loses session cursor on pause)
provider: claude
model: claude-haiku-4-5-20251001
interactive: true
worktree:
  enabled: false
nodes:
  - id: loop
    loop_group:
      until_bash: test "$(cat n 2>/dev/null || echo 0)" -ge 3
      max_iterations: 4
      fresh_context: false
      nodes:
        - id: count
          bash: n=$(( $(cat n 2>/dev/null || echo 0) + 1 )); echo $n > n; printf '%s' $n
        - id: work
          depends_on: [count]
          allowed_tools: []
          prompt: |
            PROBE iteration $count.output. Previous answer: $LOOP_PREV.gate.output
            Reply only with: earlier=<number of earlier user turns containing PROBE in this conversation>
        - id: gate
          depends_on: [work]
          approval:
            message: "Iteration $count.output: $work.output"
            capture_response: true
  1. archon workflow run body-gate-cursor and answer each pause with archon workflow respond <run-id> approve "ok".
  2. Inspect the work node's Claude session transcript per iteration and count its PROBE user turns. (The model's own earlier= answer is not reliable evidence; the transcripts are.)
  3. Variant: set until_bash: … -ge 4 and add when: "$count.output == '2' || $count.output == '4'" to the gate, so it pauses only in iterations 2 and 4.
  4. Control: the variant without the gate node (no pauses at all).

Observed (three runs, Haiku):

Case Iteration PROBE turns in the work session cache_read
gate pauses every iteration 1 / 2 / 3 1 / 1 / 1 (three separate sessions, none resumed) 5968 each (system + tools prefix only)
gate pauses in 2 and 4 1 / 2 / 3 / 4 1 / 1,2 / 1,3 / 1,3,4 7200 / 7200 / 7200 / 7475
no gate 1 / 2 / 3 / 4 1 / 1,2 / 1,2,3 / 1,2,3,4 7200 / 7200 / 7441 / 7682

Expected for the first two cases: the same continuous chain as the control.

Side note: loading the main case prints "this gate is the loop_group's terminal sink, but 'loop_group.until_bash' does not reference '$gate.output' … the loop only ends via max_iterations". In these runs the loop did end via until_bash (after 3 and 4 iterations), so the warning looks inaccurate for this shape.

Environment

  • Archon version or commit: 0.10.1 (Docker image); the relevant code is unchanged on dev at 879c99fe4d
  • Platform or adapter: CLI
  • Database: SQLite
  • OS: Linux (Docker), Claude provider via Agent SDK

Constraints and related work

  • Must remain true: $LOOP_PREV.gate.output delivery; fresh_context: true stays fresh; iteration 1 stays fresh.
  • Related issues or PRs: #2707 (successor form for interactive:), #2738, #2708.
  • Solution steering: Hint. On dev, the pause path at a terminal body gate stores sessionId: loopLastSequentialSession?.sessionId (packages/workflows/src/dag-executor.ts:5157). loopLastSequentialSession only takes the current iteration's cursor later (:5231, loopLastSequentialSession = iterCtx.lastSequentialSession), so the stored cursor is the one from before the paused iteration. Storing iterCtx.lastSequentialSession at the pause may be enough, but we have not tested a patch.