Skip to content

fix(codex): serialize startup peer state initialization - #5755

Open
ktz03 wants to merge 7 commits into
volcengine:mainfrom
ktz03:fix/codex-startup-state-lock
Open

ktz03 wants to merge 7 commits into
volcengine:mainfrom
ktz03:fix/codex-startup-state-lock

Conversation

@ktz03

@ktz03 ktz03 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Description

Codex SessionStart updates the current session's peer pin by saving its whole state. That write currently runs outside the per-session writer lock: a pending Stop worker can persist a newer transcript cursor between startup's read and save, then startup restores the old cursor and the next capture sends those turns again.

Area: Integration / Codex memory plugin. This change puts that existing update under withSessionLock and reads state inside the lock. A busy current session uses a zero-wait skip: its state and previous capture peer remain untouched, while startup profile injection for the current workspace and the existing sweep continue.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Fixes #5753, filed before the implementation.

This completes the current-session writer coverage alongside the lock introduced in #4429. It does not change #4701's stale-lock takeover or #4062's idle/ended sweep policy.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • Serialize current-session peer initialization with the existing lock, with loadState inside its callback and waitMs: 0.
  • Cover startup, clear, and resume against an occupied lock, plus a real capture subprocess paused at its loopback HTTP health request. The capture case checks the complete state, old capture peer, current workspace profile routing, and the next capture's lack of duplicates.
  • Document the busy-session behavior and raise the Codex plugin version from 0.11.4 to 0.11.5.

Testing

Current verification — main 49f7780 synchronization (2026-10-09)

Current head c1f1fd71dc9e06f7289a0bcbccb1448b535dd29a ordinarily merges exact official main 49f778011ef4f0b556d6064d4ec90343643668cf into previous head 6173e0748db3e4c01e60a14d88c0cdb15cbfe172. The original fix and regression tests and every non-owned automatic-merge entry are preserved. Upstream #5459, #5661, #5790 OpenClaw/Pi transport fixes, the gateway rename and DSH changes are retained. Beyond the clean automatic merge, only one version field in the Codex manifest changes. Only the owned Codex manifest version advances to 0.11.6, strictly newer than main 0.11.5; no other plugin release is edited after the automatic merge.

This PR's exact tree 2a566382c60194ba01398631ebcc4cc1358d1ad7 was tested separately on Windows and Ubuntu WSL with Node 24.21.0: startup commit and state-lock regressions 20 passed, shared release config/sync/HTTP contracts 97 passed, and current Codex config/marketplace/usage 41 passed on each platform. These matrices overlap and are not added together. Existing cached dependencies were reused; no fresh dependency installation occurred.

The official generator leaves tracked output unchanged, relevant module syntax passes, and the unchanged version gate passes on the real committed HEAD. Independent reviews verified actual log byte/hash/TAP results, exact tested/prepared/committed tree linkage, ordinary commit parents, metadata-only edits, retained upstream entries and source cleanliness. Earlier broader Windows failures or skips below remain historical; this refresh does not assert Windows-wide or full repository success.

Current official CI

Current head c1f1fd71dc9e06f7289a0bcbccb1448b535dd29a: 4 SUCCESS / 5 conditional SKIPPED / 0 FAILURE. All 2 current-head parent runs completed (checked 2026-10-09T06:45:07.648125+00:00). Conditional jobs did not execute.

API/CLI job 113686979393 completed 2026-10-09T06:03:04Z: SUCCESS; filesystem API 14 passed, basic API 54 passed / 1 skipped, released CLI v0.4.4 compatibility 16 passed, source CLI 25 passed / 21 skipped, with zero test failures. Skipped cases are not counted as executed coverage.

The basic-API skip is a Find request returning 401 because PR CI cannot access VLM/Embedding API keys. The 21 source-CLI skips comprise 19 unavailable upstream-authentication cases, one existing CLI/server timeout-parameter mismatch, and one unavailable skill fixture for show. These skips do not establish complete authentication or model coverage.

Conditional skips: sdk-python-tests, build, cuvs-tests, openclaw-tests, langchain-tests. These jobs did not execute.

The newly completed API/CLI job's full 550,773-byte log was read. Prior full-log evidence for the other 3 completed non-skipped jobs (282,797 bytes) is reused for the unchanged run/job metadata signatures; those old logs were not downloaded or read again. Dependency and version jobs are static checks.

The API/CLI log records official checkout 57cec7d2ed59f94eba9021fbc789a645286925ef, with exact main 49f778011ef4f0b556d6064d4ec90343643668cf and this head as parents. Its tree 2a566382c60194ba01398631ebcc4cc1358d1ad7 matches this PR's reviewed and locally tested tree.

These checks do not establish complete authentication or model coverage, a deployed OpenViking service, real host UI/IM, macOS or performance coverage. Historical results retain their named heads and platform limits.

Historical local verification — head 6173e07

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Node.js 24.21.0, Windows and Ubuntu/WSL:

  • The four added regressions fail against unchanged main 961fb463; all 20 startup tests pass with the fix on both platforms. The 16 existing startup tests retain their assertions.
  • Linux: all 193 tests in the 13-file Codex suite and all 107 tests in the seven related shared suites pass.
  • Windows: Codex has 192 passes and one existing clearEnded/markEnded race-test failure; related shared suites have 105 passes and two existing workspace-peer path-expectation failures. An untouched 961fb463 checkout reproduces the same failures with the same file lists (188/189 Codex, 105/107 shared).
  • Independent public-hook checks cover startup, clear, and resume with normal, occupied-lock, explicit-peer, bypassed, and unknown-session inputs: 15 subprocess cases pass.
  • Shared-runtime generation leaves tracked output unchanged; changed JavaScript files pass node --check; the plugin-version gate is checked against current main on the committed head.
Validation commands
node --test examples/codex-memory-plugin/scripts/session-start-commit.test.mjs
node --test examples/codex-memory-plugin/scripts/auto-capture.test.mjs examples/codex-memory-plugin/scripts/auto-recall.test.mjs examples/codex-memory-plugin/scripts/capture-utils.test.mjs examples/codex-memory-plugin/scripts/config.test.mjs examples/codex-memory-plugin/scripts/marketplace.test.mjs examples/codex-memory-plugin/scripts/ov-memory-doctor.test.mjs examples/codex-memory-plugin/scripts/pre-compact-capture.test.mjs examples/codex-memory-plugin/scripts/recall-compressor-profile.test.mjs examples/codex-memory-plugin/scripts/session-end.test.mjs examples/codex-memory-plugin/scripts/session-start-commit.test.mjs examples/codex-memory-plugin/scripts/session-state.test.mjs examples/codex-memory-plugin/scripts/startup-capture.test.mjs examples/codex-memory-plugin/scripts/uri-guard.test.mjs
node --test examples/memory-plugin-shared/agent-hook-runtime.test.mjs examples/memory-plugin-shared/profile-inject.test.mjs examples/memory-plugin-shared/pending-queue.test.mjs examples/memory-plugin-shared/workspace-peer.test.mjs examples/memory-plugin-shared/sync.test.mjs examples/memory-plugin-shared/capture-utils.test.mjs examples/memory-plugin-shared/archive-injection.test.mjs
node examples/memory-plugin-shared/sync.mjs
node --check examples/codex-memory-plugin/scripts/session-start-commit.mjs
node --check examples/codex-memory-plugin/scripts/session-start-commit.test.mjs
node --check examples/codex-memory-plugin/scripts/session-state.mjs
bash .github/scripts/check-plugin-version-bumps.sh origin/main

The focused and broader suites overlap; these counts are not additive. These tests use actual hook subprocesses, local state files and loopback HTTP fixtures. No live Codex host, deployed OpenViking service, or model was exercised. The issue's deterministic filesystem pause establishes the stale-write interleaving, not its frequency in live hosts or permanent data loss.

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Not applicable.

Additional Notes

The lock implementation, capture pipeline, and sweep rules are unchanged. Official CI results will be tracked separately from the local runs above.

Historical official CI — before head c1f1fd7

Current head 6173e074: four checks succeeded and five conditional checks were skipped; no checks remain running. API and CLI integration completed successfully on October 8 at 12:22 UTC. Its complete job log records 14 filesystem tests, 54 basic API tests with one Find/embedding-authentication skip, 16 released CLI 0.4.4 compatibility tests, and 25 source CLI tests with 21 skips (19 unavailable upstream-authentication cases, one existing timeout-parameter mismatch, and one missing skill fixture).

The plugin job passed 1,279 tests with eight skips (one opt-in live recall and seven optional Pi runtime/helper cases), plus 22 installer tests. Version and dependency checks passed. OpenClaw, build, SDK Python, cuVS, and LangChain checks were conditional skips. The actual checkout 0b3276ce merges this head with main 2819c080; these results do not establish live Codex-host, complete model/authentication, or performance coverage.

Maintenance validation (2026-10-12, main 9093583)

Synchronized this existing branch with upstream 9093583b34050619ba6f5a6a11b003b0adca15e7 after the upstream plugin releases changed. The affected release versions are now Codex 0.11.8, strictly above that main. Paired manifests, configuration, and lock metadata remain consistent.

Windows and Linux each pass 20 focused regressions, 97 release/configuration checks, and 41 Codex configuration/marketplace checks. Syntax, generated-copy consistency, and the version gate also pass on the actual commit. These suites overlap and their counts are not added. Ignored runtime dependencies are cached; this validation does not cover a live host, model, deployment, or the full server.

For current head 0eaed29b41526cca990d052127cd8954584479c3, the actual official jobs read at 2026-10-12T05:39:52.930272+00:00 report 4 in_progress. Conditional skips are not executions; queued or running jobs are not passes. Earlier CI/validation sections describe their earlier heads.

Maintenance validation (2026-10-12, main 2e706d7)

Synchronized this existing branch with upstream 2e706d7193aa47c05d986e68b61b3b994d41fa55 after the upstream plugin releases changed. The affected release versions are now Codex 0.11.9, strictly above that main. Paired manifests, configuration, and lock metadata remain consistent.

Windows and Linux each pass 50 focused regressions (including the 30 current-main capture-text regressions), 97 release/configuration checks, and 41 Codex configuration/marketplace checks. Syntax, generated-copy consistency, and the version gate also pass on the actual commit. These suites overlap and their counts are not added. Ignored runtime dependencies are cached; this validation does not cover a live host, model, deployment, or the full server.

For current head 88d6e86c110d454dbb494ce2a85646d532aa693a, the actual official job payloads collected between 2026-10-12T07:06:21.053989+00:00 and 2026-10-12T07:06:24.872846+00:00 report 4 in_progress. Conditional skips are not executions; queued or running jobs are not passes. Earlier CI/validation sections describe their earlier heads.

@ktz03
ktz03 marked this pull request as ready for review October 9, 2026 02:30
@ZaynJarvis ZaynJarvis added the agent-plugins Agent harness and plugin integrations label Oct 9, 2026

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

agent-plugins Agent harness and plugin integrations

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex SessionStart can overwrite a concurrent capture cursor

2 participants