Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(server): keep the shared Codex app-server scope alive after a tool OOM kill #18329

Mergedonly21mil(GitHub profile, opens in a new tab)merged 6 commits intomain fromrefs/pull/18329/headmerged by juliusmarminge View on GitHub

Problem

A kernel OOM kill of a tool can stop the shared Codex app-server scope, interrupting unrelated Codex threads on the same provider instance.

Change

Mark the Codex app-server as shared. When the systemd capability probe accepts OOMPolicy, launch its scope with OOMPolicy=continue, collect it automatically, and clear the launching thread’s previous OOM attribution. Ordinary scopes keep OOMPolicy=stop; older systemd keeps its existing fallback. Capability probing and both launch paths retain TimeoutStopSec=10s.

The takeover preserves @only21mil’s commits and merges current main. It replaces array-identity capability detection with an explicit result, corrects the capability log, and reduces the added tests from three to two without removing main’s eight existing tests.

Verification

  • Baseline with main’s production files: 1 failed, 9 passed; shared Codex launch still received OOMPolicy=stop. Restored implementation: 10 passed. Before/after test output.
  • Scope and Codex adapter suites: 179 passed.
  • Shared and server typechecks, targeted lint and formatting passed. Lint reports two existing unused-variable warnings outside this change.
  • A disposable 64 MiB systemd 255 scope reproduced the process behavior: stop terminated the stand-in parent with SIGTERM (143); continue kept it alive after the child received SIGKILL, with oom_kill=1, and it exited successfully. Sanitized before/after output.
  • Independent full-diff reviews: one round each from Claude Opus 5.5 and GPT-6-Sol, both with no blockers. The disclosed controller-death cleanup limitation remains outside this fix.

CI’s first run passed the server suites, build/typecheck and lint, but failed the unchanged HTML attachment preview browser test. Its focused Chromium suite passes locally (3 tests); the failed CI jobs were rerun. The rerun passed: CI’s Check, Test Web, server suites, build/typecheck and lint are green on the takeover head. A superseded fingerprint run was cancelled; its replacement succeeded.

This is a server/process change; screenshots do not demonstrate it. No live Codex session under memory pressure or UI flow was tested. Old-systemd fallback is covered through a fake user manager. App-server-as-OOM-victim cleanup, systemd-oomd, macOS, Windows, Electron desktop, iOS, and Android were not verified. If the app-server itself is killed, surviving tools can remain until they exit; this change does not add controller-death cleanup.

Original contribution: @only21mil in #18329.

Model and harness: GPT-6-Astra (tests), GPT-6.1-Sol (implementation and integration), Claude Opus 5.5 and GPT-6-Sol (reviews), through T3 Code delegated tasks and the Codex harness.

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

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

      Approvability

      Verdict: Approved at 425659b

      Macroscope's review found this PR approvable — This is a small, targeted Linux/systemd lifecycle fix that keeps shared Codex app-server scopes alive after tool OOM kills while preserving existing behavior for ordinary scopes and older systemd versions. The new behavior is isolated to Codex app-server launches and is covered by focused tests.

      You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    3. juliusmarminge added labelsmacroscope-review

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration
      • Configuration used: Path: .coderabbit.config.ts
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 84f00125-b6c1-4e8c-9844-0d6bbe6e1acc
      📥 Commits

      Reviewing files that changed from the base of the PR and between 3c38e194ecb0aeefa26421d1eac9503c86b1ab32 and 38879ae83edd6dca3ffdd842f4fb44bfc43487ca.

      📒 Files selected for processing: 4
      • apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
      • apps/server/src/process/agentScope.test.ts
      • apps/server/src/process/agentScope.ts
      • packages/shared/src/AgentScope.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

      Codex app-server launches now mark their process as shared. AgentScope applies shared-scope OOM handling when supported and updates thread OOM tracking. Tests cover systemd support and fallback behavior.

      Changes: Shared Codex app-server OOM handling

      Layer / File(s)Summary
      Shared scope contract and OOM handling
      packages/shared/src/AgentScope.ts, apps/server/src/process/agentScope.ts
      AgentScope.wrap accepts a shared flag. Shared scopes use OOMPolicy=continue when supported and are not tracked as owned by an individual thread.
      Codex shared launch and validation
      apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts, apps/server/src/process/agentScope.test.ts
      Codex app-server commands set shared: true. Tests cover OOM policy selection, shared-scope tracking, and behavior when OOM policy is unavailable.

      Priority: ➖ Normal

      Estimated code review effort: 3 (Moderate) | ~20 minutes

      Change: Bug fix

      Sequence Diagram(s)

      sequenceDiagram
        participant CodexAdapterV2
        participant AgentScope
        participant systemd
        CodexAdapterV2->>AgentScope: Wrap app-server launch with shared true
        AgentScope->>systemd: Launch shared scope with OOMPolicy=continue when supported

      Suggested reviewers: t3dotgg

      Merge Risk: ⚪ Minimal · up to 38879

      No actionable issue remains identified with the shared app-server scope change. It is ready to merge after normal checks.

      Security architecture risk: 🟡 Moderate · up to 38879

      The change prevents one tool’s memory failure from stopping every Codex thread using the shared server. It also removes automatic whole-scope termination if the shared server itself is killed. Cleanup of surviving tools in that case remains unverified, although process privileges and memory-limit configuration are unchanged.

      Retained concerns

      • Medium · reliability · inferred: OOMPolicy=continue also applies when the app-server, rather than a tool, is the OOM victim. Surviving tools may then outlive their controller and continue work or consume resources. The inspected path does not explicitly stop that shared unit on controller death. Scoped process ownership and startup slice cleanup are counterevidence, but descendant termination after the root process has died remains unverified. The introduced concern is loss of automatic OOM teardown, not removal of diagnostic tracking.
      Security review details

      Security Blast Radius

      • inferred — The directly affected scope contains the shared app-server and its descendants, serving multiple threads on one provider instance. The unchanged parent agent-slice limits constrain resource exposure when successfully applied. The evidence does not establish a new cross-user, cross-tenant, or privileged-service boundary crossing.

      Trust Boundaries and Controls

      • observed — The shared option is selected by server code, not added as a client-supplied permission. Binary, arguments, environment, and process identity follow the existing launch path. The changed control is OOM failure handling, not authentication, sandbox permissions, or credential delivery.

      Resilience and Maintainability Implications

      • inferred — Failure containment improves when a tool is killed but becomes less automatic when the shared controller is killed. Protocol termination fails pending requests and closes request-handler fibers; that is not evidence that remaining operating-system processes are terminated.

      Hardening Proposals

      • proposed — Establish a provider-instance-owned teardown guarantee for shared scopes after controller death. Validate it with surviving descendants during app-server SIGKILL, partial initialization, closure, and replacement; if process finalization does not supply that guarantee, explicitly stop the affected scope.
      Pre-merge checks: Passed 4
      Check nameStatusExplanation
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Title checkPassedThe title is concise, specific, and accurately describes the primary fix for shared Codex app-server scopes after tool OOM kills.
      Description checkPassedThe description clearly covers the problem, implementation, verification results, limitations, and test evidence. It does not use a separate Scope and approval heading or explicitly state maintainer a…
      Full details: Description check

      Explanation

      The description clearly covers the problem, implementation, verification results, limitations, and test evidence. It does not use a separate Scope and approval heading or explicitly state maintainer approval, but the focused bug rationale and linked original contribution provide sufficient context.

      ✨ Finishing Touches: 💡 1
      🧪 Generate unit tests (beta)
      • Create a new PR
      🛠️ Fix failing CI checks: 💡
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
      Comment `@coderabbitai help` to get the list of available commands.
    5. juliusmarminge assignedjuliusmarminge

    6. Taking over this one as maintainer for batch codex-04. I will preserve the contributor commits, merge current main, tighten the regression tests, and run independent reviews before pushing. No merge is planned.

    7. juliusmarminge merged thisb2cc18d

    8. juliusmarminge closed this

Sign in to join this conversation.