Skip to content

fix(provider-acp): commit the approval artifact with its runtime request - #21

Merged
Hylouis233 merged 1 commit into
mainfrom
fix/orchestration-v2-replay-approval-gate
Oct 19, 2026
Merged

Hylouis233 merged 1 commit into
mainfrom
fix/orchestration-v2-replay-approval-gate

Conversation

@Hylouis233

@Hylouis233 Hylouis233 commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

main was red on Test Server 1 for the same test in both attempts of run 39264953410:

orchestrator replay fixtures > runs tool_call_read_only_on_request/grok through OrchestratorV2 using deterministic replay
AssertionError: the approval card must show the resolved request: expected [] to deeply equal [ [ …(2) ] ]

The approval card's turn item was never persisted. The runtime request itself was created and
resolved (status === "resolved", decision === "accept"), and every other assertion in the
fixture passed, so the loss was isolated to one turn item.

Root cause: the ACP adapter emitted the approval turn item after the runtime request it
belongs to.

  • The ingestor buffers a request artifact that arrives before its request and commits both in
    one write (ProviderEventIngestor.ts, the sibling-buffer path).
  • An artifact that arrives after its request is a second write, guarded by
    EventSink.writeIfRuntimeRequestCurrent. That guard compares the request's current status
    with the caller's snapshot (EventSink.ts:379-397, current.status === expected.status).
  • The replay scenario answers the request as soon as it appears in the projection. If the answer
    lands between the ingestor's snapshot and the write's own re-read, the guard fails and the
    write is dropped without an error — the approval card silently disappears.

Why push failed and pull_request passed

This is not a content difference and not an event-type semantic:

$ gh api repos/Hylouis233/opent3code/commits/5e0a648  --jq '.commit.tree.sha[0:12]'   # PR event checked this out
b903408d3d87
$ gh api repos/Hylouis233/opent3code/commits/33d29707 --jq '.commit.tree.sha[0:12]'   # push event checked this out
b903408d3d87
$ gh api repos/Hylouis233/opent3code/commits/4e00bbf0 --jq '.commit.tree.sha[0:12]'   # PR head
b903408d3d87

The PR run checked out the synthetic merge commit 5e0a648 ("Merge 4e00bbf into 5093f0a"),
not the PR head — and it has the same tree as the pushed merge commit 33d29707.

The shard assignment is also identical, because WeightedShardSequencer splits on the committed
apps/server/src/testUtils/shardWeights.json:

$ grep -oE "src/[A-Za-z0-9_./-]+\.test\.ts" push.log | sort -u > push_files.txt
$ grep -oE "src/[A-Za-z0-9_./-]+\.test\.ts" pr.log   | sort -u > pr_files.txt
$ diff push_files.txt pr_files.txt
(no output — 152 files each, byte-identical)

Same command (vp run --filter t3 test --shard 1/3), same Node v24.22.0, same vitest v5.0.1.

⇒ The difference is a timing race, not the event type. The push run lost the race twice; the
PR run won it once. The replay fixture has no replay gate (tool_call_read_only_on_request/input.ts
uses only approve_next_runtime_request), so nothing pins the ordering.

The fix

packages/provider-acp/src/server/adapter.ts — emit the turn item before the runtime request,
in both the approval path and the user-input path:

node.updated  →  turn_item.updated  →  runtime_request.updated

The artifact is now buffered and committed atomically with the request it belongs to, which is
exactly what the sibling buffer already does for the node, and what the existing hoisting comment
in ProviderEventIngestor.ts ("hoist those artifacts ahead of the request") assumes.

This also closes a real product bug, not just a test bug: in production the user answers the
approval while the provider's artifact write is in flight, and the card can vanish under them.

Verification

New regression test in apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts asserts the
approval artifact is emitted before the pending runtime request. It is deterministic:

before the fix:  artifactIndex = -1   → FAIL ("the approval artifact must be emitted before the pending runtime request")
after the fix:   artifactIndex >= 0   → PASS

Suites run locally on this branch:

Suite Result
Adapters/AcpAdapterV2.test.ts 119 passed
Adapters/GrokAdapterV2.test.ts 20 passed
Adapters/AcpRegistryAdapterV2.test.ts 6 passed
testkit/OrchestratorReplayFixtures.integration.test.ts 144 passed (was 143 + 1 failed)

vpr typecheck exits 0, vp lint reports nothing new on the changed files, vp fmt clean.

Sibling adapters still emit the artifact after the request

The artifact-before-request order is already the convention in CodexAdapterV2.ts (both the
approval path at 5070-5083 and the user-input path at 4956-4971), which is what the ACP
adapter was deviating from. The other adapters still emit request-first and keep the same latent
race, so they can lose an artifact the same way:

Adapter Creation emit order
provider-acp (Grok, AcpRegistry, Antigravity) node → item → request fixed here
CodexAdapterV2 node → item → request already correct
ClaudeAdapterV2 node → request → item same latent race
provider-muse request → node → item same latent race
provider-pi request → node → item same latent race
provider-opencode v2 node → request → item same latent race

This PR only changes the adapter whose path actually broke CI. The other four are the same
one-line swap; say the word and I will do them in a follow-up so the fix can be verified per
provider instead of all at once.

Not included: the ENOTEMPTY flake

gitHubChangeRequestTemplate.test.ts cleans a scoped temp dir that contains a live .git, and
can fail with ENOTEMPTY on .git/objects.

It is a different class of problem and this PR does not fix it. The adapter emit order has no
effect on filesystem cleanup, and a git-config change would have no effect on provider event
ordering.

It also did not reproduce here: 0 occurrences across all 13 jobs of both attempts of
39264953410 and the PR run's Test Server 1, and 0 in 12 local loop runs of
gitHubChangeRequestTemplate.test.ts.

The likely mechanism is git commit's background git gc --auto writing into .git/objects
while the scoped temp dir is being removed. The codebase already documents that hazard and works
around it for fetch with --no-auto-gc (apps/server/src/vcs/GitVcsDriverCore.ts:1266), but
the fixtures' git commit does not. The one-line hardening would be ["gc.auto", "0"] in
apps/server/src/testUtils/gitConfig.setup.ts — the file that already exists to pin git config
for test fixtures. Left out of this PR because it is unverified here; say the word and I will add
it as a separate commit.

The ACP adapter emitted node.updated, then runtime_request.updated, then
turn_item.updated. The ingestor buffers a request artifact that arrives
before its request and commits both in one write, but an artifact that
arrives after its request is a second write guarded by
writeIfRuntimeRequestCurrent. That guard compares the request's current
status against the caller's snapshot, so once the request has been
answered the artifact write is dropped without an error and the approval
card never reaches the user.

Emit the turn item before the runtime request so the artifact is buffered
and committed atomically with the request it belongs to, which is what
the sibling buffer already does for the node.

Adds a regression test that asserts the approval artifact is emitted
before the pending runtime request.
Copilot AI balanced review requested due to automatic review settings October 19, 2026 16:28

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 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-19T16:30:14.426235Z a372f04 PR opened
ℹ️ 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.

@github-actions github-actions Bot added vouch:trusted Author has write access or is explicitly trusted by OpenT3Code. size:M 30-99 effective changed lines. labels Oct 19, 2026
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ The exact PR base did not have a successful artifact. Baseline uses the latest successful main measurement shown below.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 4.9 KiB −23 B (−0.5%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB −23 B (−1.9%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 20.9 KiB 20.8 KiB −41 B (−0.2%) 29.3 KiB ✅
Codex Live turn messages 2 1 −1 (−50.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.2 KiB 21.2 KiB 0 B (0.0%) 29.3 KiB ✅
Claude Live turn messages 2 2 0 (0.0%) 8 ✅

Baseline: 5093f0a · PR result: a372f04 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@Hylouis233
Hylouis233 merged commit 91d6577 into main Oct 19, 2026
32 of 34 checks passed
Hylouis233 added a commit that referenced this pull request Oct 19, 2026
… (follow-up to #21) (#22)

ACP adapter 之外的另外四个 adapter(Claude / Muse / OpenCode2 / Pi)有与 #21 相同的 latent 竞争:审批 turn item 发在它所属的 runtime request 之后,审批卡落到第二次独立写,被 request 状态守卫(runtimeRequestIsCurrent)静默丢弃 —— 用户点「允许」后卡片可能当场消失。

上游 pingdotgg/t3code 至今仍是 request 在前(Muse 929→934→935、Pi 1178→1184→1189、OpenCode2 v2 1637→1643、Claude 同理),故这不是上游会自行修掉的项,fork 侧必须自己带。

改法与 #21 一致:恢复代码库约定的 node.updated → turn_item.updated → runtime_request.updated,artifact 与 request 原子提交。gate 语义未改动。

🤖 由 GitHub 运维巡查自动合并
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 effective changed lines. vouch:trusted Author has write access or is explicitly trusted by OpenT3Code.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants