Skip to content

🤖 refactor: name the full-clear turn precheck and context discard in truncateHistory - #6284

Merged
ThomasK33 merged 2 commits into
mainfrom
crap/truncate-full-clear-steps
Oct 12, 2026
Merged

ThomasK33 merged 2 commits into
mainfrom
crap/truncate-full-clear-steps

Conversation

@ThomasK33

Copy link
Copy Markdown
Member

Summary

A full history clear in WorkspaceService.truncateHistory runs two blocks that were inline:

  • Before the clear, under the admission guard and refine lock, it refuses while a turn is active and discards any pending auto-retry.
  • After the clear, it requires goal acknowledgment and durably discards the context derived from the cleared transcript: file state, post-compaction carryover and sandbox kernel state.

Both blocks are now named private methods, settleTurnWorkBeforeFullClear and discardContextStateAfterFullClear, with their comments and error texts moved verbatim. Behavior is unchanged.

Background

This PR is part of the CRAP pilot on src/node/services/workspaceService.ts. CRAP = CC² × (1 − coverage)³ + CC. With #6278 and #6280, this brings truncateHistory under 30:

Function CC before CC after CRAP after (related tests)
truncateHistory 36 27 27.0
settleTurnWorkBeforeFullClear (new) 6 6
discardContextStateAfterFullClear (new) 6 6

make crap-check with related-test coverage: PASS, 0 violations, 0 warnings.

Implementation

  • Both blocks ran only for a full clear. The caller still guards each call with if (isFullClear), so the isFullClear && conditions inside became plain checks.
  • A failed check returns the same Err result, which the caller passes through unchanged.
  • The refine lock is still acquired, and held with await using, in truncateHistory itself, so it stays held across both steps and the truncation.

Validation

  • The 16 suites that call truncateHistory pass unchanged (1,101 tests).
  • Mutants that fail existing tests: ignoring a failed retry discard, keeping the post-compaction carryover, and skipping the goal acknowledgment.
  • Two mutants survive, both gaps that predate this PR:
    • Dropping the busy recheck under the lock. Reaching it needs an in-turn compaction retry that bypasses admission across an idle gap.
    • Dropping clearFileState. No test observes file state after a clear.
  • The code moved verbatim, so this PR adds no tests for those two.

Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high • Cost: $5.23

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 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 ✅ Completed 2026-10-12T22:18:39.395079Z 04981a3 New commits
🔒 Security Review ✅ Completed 2026-10-12T22:22:37.744053Z 04981a3 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.

@ThomasK33
ThomasK33 added this pull request to the merge queue Oct 12, 2026
Merged via the queue into main with commit ee7ce51 Oct 12, 2026
33 checks passed
@ThomasK33
ThomasK33 deleted the crap/truncate-full-clear-steps branch October 12, 2026 22:42
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.

1 participant