Skip to content

fix(sessions): keep reviewed runs usable after held-tool cancel or restart - #333

Merged
lg2m merged 5 commits into
mainfrom
fix/qq-checkpoint-cancel-projection-20261016
Oct 19, 2026
Merged

lg2m merged 5 commits into
mainfrom
fix/qq-checkpoint-cancel-projection-20261016

Conversation

@integrate-your-mind

@integrate-your-mind integrate-your-mind commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

What changes for users

With JEV checkpoint review on, a conversation used to become permanently unusable if a run ended while a tool call was waiting for approval. This happened on Ctrl-X/CancelRun, and also when the server restarted. Every later prompt failed before reaching the model:

tool projection for run … is unresolved: it lacks the exact tool-result projection needed to preserve its history; start a new session to continue without changing this history

After this change, that history replays the unfinished call with an explicit cancelled/interrupted result, the same as a run without review, and the next prompt reaches the provider. If a JEV verdict was actually recorded for a call in that turn, the refusal still applies, so a verdict never silently drops out of history.

Why / design

  • Root cause:
    • A tool turn's tool_results_projection_json is written only on ToolResultsProjected, after the tools finish and the checkpoints run (run_loop.rs checkpoint_tools → close_tool_turn).
    • Cancel and restart settle a held call without reaching that point.
    • assemble_model_context then set checkpoint_projection_required for every turn of a checkpoint-enabled run, so append_run_turns raised ToolProjectionUnavailable.
  • Fix: one SQL expression in transcript.rs, on the read side. It also releases already-affected histories that have no recorded verdict, without changing the store.
    • If a saved projection exists: 0. The flag is consulted only when no projection exists.
    • If the descriptor is valid JSON with an absent or null checkpoint: 0. No review can exist.
    • Otherwise, including an invalid or NULL descriptor: EXISTS a checkpoint_reviewed event for a call of that run and turn. This fails closed.
    • Event scans happen only for reviewed turns that lack a projection, so the common path never touches events.
  • Known limit, still fail-closed: a turn that mixes an already-settled or denied call with a held call gets "Unavailable" checkpoint events from record_unreviewed_checkpoints on cancel or restart. That session still refuses, as before. Not covered here.
  • Authorship: the patch was written by QQ 0.1.7 (openai-codex/gpt-6.1-sol) in a visible tmux session as one task conversation. Claude wrote the failing reproduction (ee56d1fc8), directed and approved each action, and verified the result.

How verified

  • New tests, failing on main and passing here:
    • sessions::tests::projection::cancelling_a_reviewed_run_awaiting_tool_approval_keeps_the_session_usable
    • …::restarting_during_a_reviewed_runs_tool_approval_keeps_the_session_usable
  • They assert that the continuation request keeps "edit the note", the call_0 write_file call, its matching cancelled/interrupted error result, and "continue", in that order. This comes from an independent review finding.
    • Mutation check: a wrong repair that skips the turn fails both tests.
  • Guard tests unchanged and passing:
    • ab2_checkpoint_review_without_exact_projection_cannot_lose_its_verdict
    • both ab2_ambiguous_history_* tests
    • ab2_oversized_checkpoint_feedback_persists_the_corrective_request, including its crash-gap half
    • the rest of sessions::tests::projection
  • cargo nextest run -p qq-core -E 'test(/reviewed_run|projection::/)': 11 passed.
  • cargo xtask check on the pinned 1.97.1 toolchain: fmt, lint and clippy pass.
    • Test gate: 2104 run, 2061 passed. Locally, 12 tests fail identically on base 3e34eea2c with this diff reverted; they are environmental on this Mac (Darwin PATH_MAX/SUN_LEN search and socket fixtures, a sandboxed keyring/routing setup, one deadline timeout). The other 31 pass with a short TMPDIR.
    • CI is the authoritative gate.
  • Independent read-only review: no defects found. It confirmed checkpoint_reviewed is the only durable verdict record, and checked the JSON paths, the workspace key and that the column has no other readers.

Impact

  • Performance: the history-assembly query is touched. Turns with a saved projection and turns of unreviewed runs short-circuit with no events scan. At b8d435ebb, reviewed turns without tool calls still reached the events probe; this was the Codex finding r4304943702, and the earlier wording of this line overstated the short-circuit. 34618e53 adds the tool_calls guard for those turns. A deterministic regression for that guard is in progress and not yet pushed. The remaining EXISTS, which applies only to reviewed turns with tool calls and no saved projection, filters events by the workspace_id primary-key prefix and has no JSON expression index. The timing below is a local maintainer measurement, not a CI assertion.
  • Compatibility: this diff changes no protocol, store schema or descriptor. The branch is at main's protocol 35 / store schema 58 / descriptor 15. Published v0.1.7 is protocol 32 / store 50, so replacing it with any current-main build migrates the store. That jump is main's, not this PR's, and it needs its own migration/rollback qualification before adoption.
  • Docs: none; this is internal recovery behaviour.

Acceptance status (not complete)

Refs #335. This PR does not close it.

  • Done: source repair with real red→green tests, CI "fmt, lint, clippy, tests, smoke" green at b8d435ebb, and an independent read-only review with no defects found.
  • Not established:
    • JEV evaluation: the real JEV final review of QQ's evaluation run returned InsufficientEvidence (final:3, then final:8). JEV routing was off for that run. The full self-evaluation loop is not accepted.
    • Mixed-call case: a turn with an already-settled or denied call plus a held call still refuses after cancel or restart. That refusal is fail-closed, but no test executes it.
    • Live recovery: whether the originally affected live run recovers is unverified, because the live store was not read.
    • Adoption: the candidate build is staged only. It is not installed, and the store 50→58 migration (current main) and its rollback are unqualified.
  • Source CI is not runtime or installation acceptance.

Maintainer follow-up (2026-10-17)

  • Merged current main (2f585b0d), no conflicts.
  • 34618e53: reviewed turns without a projection and without tool calls short-circuit via the indexed tool_calls(run_id, turn_ordinal, …) lookup and never reach the events probe (synthetic 300k-event store: 1.98 s → 0.002 s for 21 such turns).
  • Kept despite the decisions redesign: read-side only, no schema/wire change, unbricks already-affected sessions, does not touch the decision seam.
  • cargo nextest run -p qq-core -E 'test(/projection|reviewed_run/)': 17/17 pass; the two new tests fail with main's transcript.rs. Smoke 8/8.
  • Unrelated: qq headless::tests::closing_goal_host_drains_accepted_work_without_admitting_successors also times out locally on unmodified main.

…cel or restart

A JEV-reviewed run whose tool call is held for approval leaves its tool
turn without a projection when cancelled or when the server restarts;
every later prompt in that conversation then fails with
ToolProjectionUnavailable before reaching the provider.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011YSSvkVJ34kvxKGsmK71uZ
…start

With JEV checkpoint review on, cancelling a run (or restarting the server)
while its tool call awaited approval left the tool turn without a saved
tool-result projection. History assembly required that projection for every
turn of a checkpoint-enabled run, so every later prompt failed with
ToolProjectionUnavailable before reaching the provider.

Require the exact projection only when a checkpoint_reviewed event was
actually recorded for one of the turn's calls. A turn whose calls were never
reviewed replays with explicit interrupted results, as an unreviewed run does.
A recorded verdict still fails closed. Saved projections and valid
no-checkpoint descriptors short-circuit, so the common path never scans
events; an invalid descriptor still falls through to the event check.

The reproduction helper now asserts that the continuation request keeps the
original prompt, the call_0 write, its cancelled/interrupted result and the
new prompt in order (independent review finding F1); a deliberately wrong
repair that drops the turn fails it.

Patch authored by QQ 0.1.7 (openai-codex/gpt-6.1-sol, plan ca8c2a69) in a
visible tmux session on the user's server; directed, verified and committed
by Claude.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_011YSSvkVJ34kvxKGsmK71uZ
@integrate-your-mind
integrate-your-mind marked this pull request as ready for review October 17, 2026 23:18
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-19T05:12:44.927225Z 700f3fa New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b8d435ebbf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 34618e5384

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@lg2m
lg2m merged commit 7750ec7 into main Oct 19, 2026
6 checks passed
@lg2m
lg2m deleted the fix/qq-checkpoint-cancel-projection-20261016 branch October 19, 2026 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants