Skip to content

🤖 refactor: define inactive compaction cancellation state - #4140

Merged
ThomasK33 merged 7 commits into
mainfrom
codex/effect-cancellation-state-core
Sep 8, 2026
Merged

🤖 refactor: define inactive compaction cancellation state#4140
ThomasK33 merged 7 commits into
mainfrom
codex/effect-cancellation-state-core

Conversation

@ThomasK33

@ThomasK33 ThomasK33 commented Sep 8, 2026

Copy link
Copy Markdown
Member

Introduce an inactive cancellation state core for the agent-loop refactor. It keeps cancellation nonce and retry ownership across failed persistence, distinguishes witnessed replacement from unfinished deletion, and prevents stale narrowing or retirement from superseding newer work.

Storage is an injected contract. A later adapter must enforce shared-lock nonce/frontier comparison, verify replacement witnesses, and repair malformed storage safely. No runtime caller uses this core yet; Stop and recovery behavior are unchanged by this PR.

This independent H1 prerequisite replaces part of closed #4121. It does not depend on the pending-attachment protocol, so it can be reviewed separately without unrelated ancestry.

Validation: 48 behavioral tests pass, including narrowing versus retirement, fallback read rejection versus newer Stop/retry, foreign narrowing after failed witnessed deletion, and reordered reads and repairs. A newer accepted read supersedes older results; a merely pending successor cannot hide valid cancellation or repair errors. Final full static checks and independent review pass. Nix formatting was skipped because Nix is unavailable. Diff: 318 production lines and 727 test lines in two new files.

Risk is limited while inactive. Injected-adapter tests prove state-machine invariants, not filesystem durability or cross-process compare-and-swap; the real adapter and complete runtime activation remain separate deliveries.


Generated with xum • Model: unavailable • Thinking: unavailable • Cost: $unavailable

@chatgpt-codex-connector

This comment has been minimized.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Please review this inactive state core's nonce/retry ownership, witnessed retirement, failed deletion debt and post-await identity checks. Filesystem adapter and complete runtime activation are separate prerequisites; no current Stop/recovery caller is switched here.


Generated with xum • Model: unavailable • Thinking: unavailable • Cost: $unavailable

@chatgpt-codex-connector

This comment has been minimized.

@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: 52a5febaa0

ℹ️ 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".

Comment thread src/node/services/compactionCancellation.ts
Comment thread src/node/services/compactionCancellation.ts Outdated
@ThomasK33
ThomasK33 force-pushed the codex/effect-cancellation-state-core branch from 52a5feb to 96cab2a Compare September 8, 2026 14:13
@ThomasK33

Copy link
Copy Markdown
Member Author

Addressed 3958384487: fallback publication now rechecks the captured mutation and pending promise after rejection resumes, preserving a newer Stop or retry.

Addressed 3958384495: failed witnessed retirement for A no longer blocks narrowing a freshly read B. B's own failed writes remain blocking and retryable.

Four deterministic regressions failed before the fix. All 36 focused core tests and final full static checks pass; independent review approved the 18 added/1 removed production lines. No filesystem behavior or runtime activation is added.

@codex review


Generated with xum • Model: unavailable • Thinking: unavailable • Cost: $unavailable

@chatgpt-codex-connector

This comment has been minimized.

@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: 96cab2a8c9

ℹ️ 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".

Comment thread src/node/services/compactionCancellation.ts Outdated
@ThomasK33

Copy link
Copy Markdown
Member Author

Addressed finding 3958898439: read completions now track the newest accepted read generation as well as local mutation ownership. Once B is accepted, an older A cannot overwrite B, expose its stale error, or start fallback cancellation. A merely pending B does not hide A's valid cancellation or repair failure.

All 48 focused behavioral tests pass, including reordered success/error completions, repair ownership, pending-successor controls, and replacement fallback races. Independent review approved this bounded change: 23 added and 5 removed production lines.

@codex review


Generated with xum • Model: unavailable • Thinking: unavailable • Cost: $unavailable

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 01b0ea1a57

ℹ️ 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

This comment has been minimized.

Wait for the warning's visible state after opening it so the assertion can tolerate the app entrance transition without accepting persistent invisibility.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---

_Generated with `xum` • Model: `unavailable` • Thinking: `unavailable` • Cost: `$unavailable`_

<!-- mux-attribution: model=unavailable thinking=unavailable costs=unavailable -->

Change-Id: Ieeb9c6b96af089dab27156d43a7f54fcb9b38dbe
Keep cancellation nonce and retry ownership across failed persistence. Model witnessed retirement and deletion debt without activating runtime behavior; a later adapter supplies shared-lock storage and acceptance witnesses.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---

_Generated with `xum` • Model: `unavailable` • Thinking: `unavailable` • Cost: `$unavailable`_

<!-- mux-attribution: model=unavailable thinking=unavailable costs=unavailable -->

Change-Id: Ic12b78c45520044eba01a6857ada8179c91a62d7
Recheck fallback ownership after read rejection and let foreign cancellation narrowing bypass obsolete witnessed deletion debt.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---

_Generated with `xum` • Model: `unavailable` • Thinking: `unavailable` • Cost: `$unavailable`_

<!-- mux-attribution: model=unavailable thinking=unavailable costs=unavailable -->

Change-Id: Ib8a1b50afce050febe46cbb9a110bc1686832d69
Reject stale completions after an accepted successor without treating an in-flight read as evidence that cancellation is absent. Preserve error, repair, and replacement fallback ownership across the same boundary.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---

_Generated with `xum` • Model: `unavailable` • Thinking: `unavailable` • Cost: `$unavailable`_

<!-- mux-attribution: model=unavailable thinking=unavailable costs=unavailable -->

Change-Id: Icd8b3f1eb6e009c8f843712a08a4ac4c75ecd836
@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

Prioritizing this bottom layer for merge. Integrated the shared CI fixes: #4143 is merged and the validated one-line Storybook fix #4145 is queued immediately ahead. All three cancellation-core commits remain identical by git range-diff, including the reviewed accepted-read ordering fix. All 48 focused tests and full static checks pass on the combined tree. No new behavior or scope was added. The storage layer remains untouched until this parent lands.


Generated with xum • Model: unavailable • Thinking: unavailable • Cost: $unavailable

@ThomasK33
ThomasK33 force-pushed the codex/effect-cancellation-state-core branch from 01b0ea1 to 65826f4 Compare September 8, 2026 15:50
@chatgpt-codex-connector

This comment has been minimized.

@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: 65826f476d

ℹ️ 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".

Comment thread src/node/services/compactionCancellation.ts Outdated

@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: 65826f476d

ℹ️ 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".

Comment thread src/node/services/compactionCancellation.ts
Storage supplies the exact committed record, including inherited retention, through a synchronous receipt before lock release or cleanup. Apply cache and read invalidation there so delayed settlement cannot resurrect retired state or discard a newer foreign cancellation. Preserve existing public mutation outcomes.

All 60 core tests and full static checks pass. Regressions cover inherited retention, stale predecessor reads, both foreign-successor completion orders, and failed or superseded publication. Independent review approved.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---

_Generated with `xum` • Model: `unavailable` • Thinking: `unavailable` • Cost: `$unavailable`_

<!-- mux-attribution: model=unavailable thinking=unavailable costs=unavailable -->

Change-Id: Ie0a730120182d8ccce38ae4e2b3ae4ad74c85cb9
@ThomasK33

Copy link
Copy Markdown
Member Author

Addressed both findings:

  • 3959825072: storage now supplies the exact committed snapshot, including retention inherited under its lock, through a synchronous receipt. Core state uses that snapshot rather than the submitted record.
  • 3959828294: committed retirement invalidates predecessor reads at that receipt, before lock release or cleanup. Later Promise settlement cannot overwrite a newer accepted read. Regressions also cover a foreign successor completing before and after delayed acknowledgment.

All 60 core tests and full static checks pass; independent review approved. The production delta is 25 changed lines. Existing public mutation outcomes remain strings, and runtime activation remains separate. H2a is integrating this receipt contract while retaining its validated lease guards; both members of this phase will be queued together once ready.

@codex review


Generated with xum • Model: unavailable • Thinking: unavailable • Cost: $unavailable

@chatgpt-codex-connector

This comment has been minimized.

@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: f374bf0296

ℹ️ 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".

Comment thread src/node/services/compactionCancellation.ts Outdated
Preserve unknown state after superseded reads and refresh once before replacement. Reject another overlap or unresolved persistence; unsupported storage records bypass fallback.

Validation: 71 targeted tests, full static checks, and independent review pass.
Signed-off-by: Thomas Kosiewski <tk@coder.com>

---

_Generated with `xum` • Model: `unavailable` • Thinking: `unavailable` • Cost: `$unavailable`_

<!-- mux-attribution: model=unavailable thinking=unavailable costs=unavailable -->

Change-Id: I3581c075367f653fba39e6dedf8f62c350952652
@ThomasK33

Copy link
Copy Markdown
Member Author

Addressed 3960295475: a superseded read leaves state unknown, never evidence that the cancellation file is absent. Replacement performs one fresh read and propagates failure. A second overlap or outstanding persistence rejects conservatively instead of returning a tentative Stop. Unsupported or oversized storage records explicitly bypass replacement fallback.

The bounded refresh race reproduced before the final guard. All 71 targeted tests and full static checks pass; independent review approved. The change is 26 production lines, with coverage for both overlap completion orders and persistent failures. No runtime activation was added.

@codex review


Generated with xum • Model: unavailable • Thinking: unavailable • Cost: $unavailable

@chatgpt-codex-connector

This comment has been minimized.

@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: 0a367ba750

ℹ️ 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".

Comment thread src/node/services/compactionCancellation.ts Outdated
Comment thread src/node/services/compactionCancellation.ts
Return current cancellation state after replacement reads and invalidate earlier reads synchronously when repair commits. Preserve successor state and bounded refresh behavior.

Both races reproduced before the fix. All 77 core tests, full static checks, and independent review pass.

Signed-off-by: Thomas Kosiewski <tk@coder.com>

---

_Generated with `xum` • Model: `unavailable` • Thinking: `unavailable` • Cost: `$unavailable`_

<!-- mux-attribution: model=unavailable thinking=unavailable costs=unavailable -->

Change-Id: I77e0089454adfee985ba8aaa72cf51c2a28f5100
@ThomasK33

Copy link
Copy Markdown
Member Author

Addressed both read-ownership findings:

  • 3960787547: replacement reads return the current effective state after the await, so a Stop committed in that gap cannot be replaced by the earlier snapshot.
  • 3960787557: the repair receipt immediately clears obsolete cached retention and advances accepted-read ownership. Earlier reads cannot restore removed state during cleanup, and the repair acknowledgment cannot overwrite a newer successor.

Both reported races reproduced before the fix. All 77 core tests and full static checks pass; independent review approved. This round changes ten production lines using existing ownership counters. Generic refusal, bounded refresh, and the inactive scope remain intact.

@codex review


Generated with xum • Model: unavailable • Thinking: unavailable • Cost: $unavailable

@chatgpt-codex-connector

This comment has been minimized.

@ThomasK33

Copy link
Copy Markdown
Member Author

@codex review

The current head is 4684034. Code and security status rows report completion, all review threads are resolved, and CI passes, but there is no explicit current-head code approval or PR-description thumbs-up. Please review this unchanged candidate and provide the normal approval or actionable findings. No code changes have been added since the 77-test/full-static validated read-ownership fix.


Generated with xum • Model: unavailable • Thinking: unavailable • Cost: $unavailable

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 4684034bb7

ℹ️ 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

This comment has been minimized.

@ThomasK33
ThomasK33 added this pull request to the merge queue Sep 8, 2026
Merged via the queue into main with commit 50021c7 Sep 8, 2026
19 of 20 checks passed
@ThomasK33
ThomasK33 deleted the codex/effect-cancellation-state-core branch September 8, 2026 19:40
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