Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): preserve native Codex subagent lifecycle in v2 #11996

Closedlnieuwenhuis(GitHub profile, opens in a new tab)wants to merge 3 commits intot3code/codex-turn-mapping fromrefs/pull/11996/headopened View on GitHub

Codex collaboration events use native statuses that the V2 adapter was treating as running, leaving interrupted, shut-down, and missing children active and initializing children incorrectly marked as executing.

Map all seven native statuses explicitly. Keep initializing children protected from idle release and promote them on their first native turn, including when the child start arrives before its spawn snapshot. Settle both registration execution nodes for children that terminate before their first native turn; native-turn events retain ownership once execution starts.

Targets t3code/codex-turn-mapping for #2829. Refs #11164. #11608 addresses the separate client-runtime path on main; this fixes the V2 provider adapter.

Validation: 91 adapter replay tests pass, including regressions observed failing before the fix; scoped server typecheck and targeted lint/format pass. Independent adversarial reviews found lifecycle gaps that were fixed with regression coverage. A subsequent Macroscope finding about children terminating before their first native turn was reproduced and fixed; a fresh adversarial review of that fix reported no findings. Changed files pass the secrets scan. No live-provider verification.

The repository scanner config retains default rules and exempts only the exact synthetic idempotencyKey fixture in packages/effect-codex-app-server/src/protocol.test.ts, which otherwise flags twice in the inherited V2 history. Negative controls confirm other values, keys, paths, and credential rules remain detected.

Implemented with GPT-6 Astra via Codex.

    1. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    2. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Macroscope has since reviewed this pull request. An earlier review was skipped by a cost limit; a review has now completed, so that notice no longer applies.

    3. macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      Approvability

      Verdict: Approved at 7630e9e

      Macroscope's review found this PR approvable — This is a contained Codex adapter bug fix that corrects native subagent status and lifecycle projection, including idle-retention behavior. The changes add no schema or deployment surface and include broad replay coverage for status and event-order cases.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    4. Rebased this PR onto the current t3code/codex-turn-mapping at 4a4c22b29c.

      What changed on the branch

      • The two "reconcile" merge commits (e194c16dca, 6603dbc876) were dropped. They carried a stale copy of the v2 branch and would have reverted recent v2 work (plus a .gitleaks.toml change that does not belong here). Only your three content commits remain, cherry-picked in order: map native statuses, retain initializing subagents, settle nodes before native turns. All three applied cleanly against the current CodexAdapterV2.ts; no manual conflict resolution was needed.
      • No code edits of my own. I checked that "pending" is still a valid OrchestrationV2Subagent["status"] in packages/contracts/src/orchestrationV2.ts, and that v2's "Map nested Codex subagent threads correctly" change does not overlap with your agentsStates mapping (it only changed node parent ids), so each native status is mapped exactly once via codexSubagentStatus.

      Verified

      • vp test run src/orchestration-v2/Adapters/CodexAdapterV2.test.ts in apps/server: 108 passed.
      • vpr typecheck in apps/server: clean (only pre-existing Effect suggestions).

      Left for you / a maintainer

      • If you need to pick up future v2 changes, please rebase rather than merging the base branch in; the merge-based reconcile is what caused the revert risk.

      Rebased and touched up by a maintainer's agent; a human will re-review.

    5. juliusmarminge requested changes

      @@ -5440,3 +5440,14 @@
      54405440 ),
      54415441 );
      54425442
      5443+ for (const [nativeStatus, expectedStatus, terminal] of [
      5444+ ["pendingInit", "pending", false],
      5445+ ["running", "running", false],
      5446+ ["interrupted", "interrupted", true],
      5447+ ["completed", "completed", true],
      5448+ ["errored", "failed", true],
      5449+ ["shutdown", "cancelled", true],
      5450+ ["notFound", "failed", true],
      5451+ ] as const) {
      5452+ for (const nativeTurnStarted of [false, true]) {
      5453+ it.effect(
      juliusmarmingecommented

      it.effect.each

      @@ -5442,0 +5559,21 @@
      5559+ const projectedItems = harness.events
      5560+ .filter(
      5561+ (
      5562+ event,
      5563+ ): event is Extract<ProviderAdapterV2Event, { type: "turn_item.updated" }> =>
      5564+ event.type === "turn_item.updated" && event.turnItem.type === "subagent",
      5565+ )
      5566+ .slice(-2);
      5567+ assert.lengthOf(projectedItems, 2);
      5568+ for (const event of projectedItems) {
      5569+ assert.equal(event.turnItem.status, taskStatus);
      5570+ assert.deepEqual(event.turnItem.completedAt, terminal ? now : null);
      5571+ }
      5572+ }).pipe(Effect.provide(Layer.merge(idAllocatorLayer, NodeServices.layer))),
      5573+ ),
      5574+ );
      5575+ }
      5576+ }
      5577+
      5578+ for (const childStartsFirst of [false, true]) {
      5579+ it.effect(
      juliusmarmingecommented

      it.effect.each

    6. Superseded by merged PR #12974, which includes the Codex V2 native subagent-status lifecycle fixes and broader settlement/reopen handling. Closing this older implementation.

    7. juliusmarminge closed this

Sign in to join this conversation.