Skip to content

fix(agent-status): preserve Codex turn state across compaction - #31947

Open
tigerlaibao wants to merge 1 commit into
stablyai:mainfrom
tigerlaibao:fix/codex-compaction-status
Open

tigerlaibao wants to merge 1 commit into
stablyai:mainfrom
tigerlaibao:fix/codex-compaction-status

Conversation

@tigerlaibao

Copy link
Copy Markdown

ELI5

After Codex compacts a conversation, a task that already finished can start spinning again in Orca. A task still running can also lose the information Orca needs to recognize its eventual finish. This change leaves the current task alone when Codex reports compaction, so completed tasks stay Done and running tasks can finish normally.

What Changed

  • Ignore Codex SessionStart events whose source is compact, before the provider event adapter can reset a session or relabel an ended turn.
  • Preserve the lead turn ID, transcript cursor, subagent roster, prompt, and pending human question. Other startup/resume events retain their existing behavior.
  • Add deterministic regressions for finished turns with and without a compact hook turn ID, the next real prompt, a live turn completing from its transcript after compaction, and a pending question.
  • Extend the existing review-completion integration test to assert that compaction preserves Done, both locally and through the relay.

Why

Compaction is not a new user turn or a new Codex process. Processing it as startup can reopen a completed task and discard the turn ID used by the completion fallback from #28860. Ignoring that exact event preserves the existing facts without adding polling, timeouts, stored flags, or a protocol change. Closed #22753 described the same compact-event guard, but current main still lacks it.

Open PRs were checked before starting a separate contribution:

Linked Issue

Fixes #31944.

Visual Proof

The same synthetic UserPromptSubmit → Stop → SessionStart(source=compact) sequence was sent through the real authenticated hook endpoint in isolated hidden Electron instances, using Playwright. Every test window was asserted hidden. These captures show the normal host listener → IPC → store → sidebar path; no real Codex model request was made and no user session was modified.

Before: compact reopens a finished task After: the completed task stays Done
Before: completed Codex task becomes Working after compact After: completed Codex task remains Done after compact

Testing

  • I manually tested these changes locally. Validation used automated hidden Electron replay rather than a live interactive Codex run.
  • Automated tests added/updated.

On macOS arm64, based on main ea60ec5d7c:

  • The four new shared-listener regressions fail with the compact guard removed and pass with it present.
  • Five focused test files: 65 tests passed, including the real local/relay HTTP completion flow.
  • Hidden Electron before/after replay: one passing run against unmodified main and one passing run against the fix, asserting the expected rendered Working/Done states and hidden-window policy.
  • pnpm lint passed; pnpm tc passed all four projects; final pnpm tc:node and changed-code quality gate passed.
  • Full pnpm test --maxWorkers=2 --bail=1 stopped at an unrelated /var versus /private/var assertion in src/main/runtime/orca-runtime-tests/repository-project-operations.spec.ts:190. The same individual test fails with the production compact guard removed, against the unchanged main implementation.
  • Full pnpm build completed the desktop and web bundles and built-skill verification, then failed in mobile-web compilation because this checkout lacks mobile dependencies including react-native-web and expo-router. Both before/after Electron E2E bundles built successfully.

Physical Linux/Windows and a real SSH host were not exercised. The relay integration test exercises the shared execution-host normalization and forwarding path.

AI Disclosure

OpenAI Codex (GPT-6) assisted with investigation, implementation, regression coverage, hidden Electron evidence, and self-review.

Review

Self-review covered cross-platform behavior, local/SSH/remote normalization, other agent integrations, performance, UI behavior, and security. The provider-specific guard uses existing source parsing, performs no I/O or process work, and changes no schema, IPC channel, credentials, or dependencies. Other providers and real Codex startup/resume events are unchanged. Mobile and mixed-version clients continue receiving the existing host-owned status vocabulary. No Git assumptions are introduced, so folder workspaces follow the same path.

Agent skill upstream boundary

  • Not applicable; this change copies no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

This prevents future compaction events from corrupting status; it does not migrate already-corrupted in-memory rows. Wrong-project attribution is tracked by the existing PRs cited above and is outside this fix.

Author

GitHub: @tigerlaibao. X/Twitter: not provided.

Checklist

  • This PR is small and focused.
  • I explained what changed and why, including the user-facing before/after and mechanism.
  • Before/after screenshots attached for the behavior change.
  • Self-reviewed for correctness, security, and performance.
  • Cross-platform, SSH/remote, folder-workspace, and mobile impact considered.
  • Full pnpm lint, pnpm typecheck, pnpm test, and pnpm build are all green. Lint and typechecks passed; full-test and mobile-build limitations are documented above for CI/reviewer follow-up.

@coderabbitai

coderabbitai Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c6dbf32e-8019-4128-a638-f6c8e84eda22
📥 Commits

Reviewing files that changed from the base of the PR and between ca9abc6 and 63ee660.

📒 Files selected for processing: 3
  • src/main/agent-hooks/server-codex-review-turn-end.test.ts
  • src/shared/agent-hook-listener/providers/codex-compaction-status.test.ts
  • src/shared/agent-hook-listener/providers/codex-events.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

📝 Walkthrough

Compact Codex SessionStart hooks now return no event before turn ID or transcript-end checks. New listener tests cover completed turns, live turns, and pending human questions. Review-turn tests cover compaction with and without the relay, including delayed hooks from ended turns.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 63ee6

The change is mergeable after normal checks; no actionable defect was established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preserving Codex turn state during compaction.
Description check Passed The description follows the repository template and explains the user impact, implementation, rationale, linked issue, visual evidence, tests, limitations, AI usage, review scope, and checklist status…
Linked Issues check Passed The PR satisfies the active coding requirements in #31944. codexHookEventForEndedTurn drops Codex SessionStart events when source is compact, before ended-turn processing. The added tests veri…
Out of Scope Changes check Passed The changed production code is limited to the Codex compact-event guard. The new and updated tests directly cover the behavior required by #31944, including local and relay paths. No unrelated feature…
Full details: Description check

Explanation

The description follows the repository template and explains the user impact, implementation, rationale, linked issue, visual evidence, tests, limitations, AI usage, review scope, and checklist status. Known full-test and mobile-build failures are documented with their reported causes.

Full details: Linked Issues check

Explanation

The PR satisfies the active coding requirements in #31944. codexHookEventForEndedTurn drops Codex SessionStart events when source is compact, before ended-turn processing. The added tests verify that a finished turn remains Done, a live turn retains its turn and subagent state and settles from transcript completion, and a pending human question remains waiting. The tests also verify that a later prompt still starts normally and that local and relay completion paths preserve Done. The PR does not change unrelated startup/resume behavior or add a status protocol. Closed #22753 is historical context only.

Full details: Out of Scope Changes check

Explanation

The changed production code is limited to the Codex compact-event guard. The new and updated tests directly cover the behavior required by #31944, including local and relay paths. No unrelated feature, provider, protocol, dependency, or attribution change is present in the reviewed diff.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

This branch has not been deployed

No deployments
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.

[Bug]: Codex compaction can reopen a finished task as Working

1 participant