Skip to content

Regression: Codex generation fencing breaks sequential runEmbeddedAgent calls with stable sessionKey #108769

Closed

Description

@cavit99

Summary

OpenClaw 2026.7.1 introduced Codex session-generation fencing that can break existing runEmbeddedAgent callers which reuse a logical sessionKey while creating a fresh sessionId for each isolated run.

The first invocation can succeed, while subsequent invocations fail locally before model execution with:

Codex session generation is no longer current: <sessionId>

This is an observable compatibility change in the public plugin runtime API.

Regression range

Minimal reproduction

Using the Codex harness, invoke api.runtime.agent.runEmbeddedAgent(...) twice with:

  • the same stable sessionKey
  • a newly generated sessionId for each invocation
  • an isolated temporary transcript/session target

Conceptually:

for (let attempt = 0; attempt < 2; attempt += 1) {
  const sessionId = `isolated-task-${crypto.randomUUID()}`;
  await api.runtime.agent.runEmbeddedAgent({
    sessionId,
    sessionKey: "tool:isolated-task",
    runId: sessionId,
    prompt: "Return a short response",
    // normal provider/model/workspace parameters omitted
  });
}

The first generation can claim the stable key. A later invocation has no binding for its fresh physical session and fails to reclaim the previous generation. In the 2026.7.1 distribution, the exception is thrown by the Codex thread lifecycle when reclaimCurrentCodexSessionGeneration(...) returns false.

Removing sessionKey so that each isolated invocation uses its own identity avoids the failure.

Why this is difficult for plugin authors

  • RunEmbeddedAgentParams publicly accepts both sessionId and optional sessionKey.
  • The SDK documentation does not explain their required lifecycle relationship for Codex.
  • The SDK example does not discuss persistent versus isolated session identity.
  • The first invocation succeeds; there is no up-front validation of the combination.
  • There is no doctor or lint warning for affected plugins.
  • The exception does not tell callers whether to omit sessionKey, reuse sessionId, or perform an explicit generation transition.
  • A single post-upgrade smoke run will pass and therefore miss the regression.

This is not limited to plugins migrated from the legacy pi harness. Any current or future embedded Codex caller can encounter it. The same exception is already visible in the bundled Active Memory failure reported in #106957, although that issue has additional timeout and duplicate-recall behavior.

Expected improvement

At least one of:

  1. Preserve compatibility for isolated embedded calls.
  2. Reject incompatible identity combinations immediately with actionable guidance.
  3. Document the sessionId / sessionKey lifecycle and how callers intentionally rotate a physical generation.
  4. Add upgrade diagnostics for affected plugins.
  5. Add a regression test covering two sequential embedded Codex invocations with a stable logical key and rotating physical IDs.

Environment

  • Reproduced on OpenClaw 2026.7.1
  • macOS arm64
  • Native Codex harness through api.runtime.agent.runEmbeddedAgent(...)
  • Failure occurs before model generation and is independent of the selected OpenAI model

Related: #101210, #106957.

Activity

  1. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    on Jul 16, 2026
  2. clawsweeper commented on Jul 16, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 16, 2026, 4:28 AM ET / 08:28 UTC.

    Summary
    Keep this issue open: the report identifies a credible shipped plugin-runtime regression, and current main still contains the post-first-run generation check that can reject a fresh physical session under a stable logical key. The related Active Memory issue has overlapping stale-generation symptoms but also separate timeout and duplicate-recall behavior, so it does not supersede this narrower report. citeturn975881search0turn338428search3.

    Reproducibility: yes. at source level: two sequential embedded Codex calls using one stable sessionKey and fresh sessionId values reach the generation-reclaim failure path after the first call. A focused live current-main run remains outstanding.

    Root-cause cluster
    Relationship: canonical
    Canonical: #108769
    Summary: This issue isolates the stable-key/rotating-ID generation-fencing regression; the Active Memory report overlaps on the final error but includes additional timeout and duplicate-run behavior.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    This is a bounded compatibility regression with a clear Codex lifecycle surface and regression-test shape, but the repair must first prove it preserves concurrent stale-generation fencing.

    Review details

    Best possible solution:

    Preserve the shipped plugin-runtime identity combination with a narrowly defined safe transition for sequential isolated generations, add two-call regression coverage, and document when callers should reuse or rotate sessionId and sessionKey.

    Do we have a high-confidence way to reproduce the issue?

    Yes at source level: two sequential embedded Codex calls using one stable sessionKey and fresh sessionId values reach the generation-reclaim failure path after the first call. A focused live current-main run remains outstanding.

    Is this the best way to solve the issue?

    Yes in direction, but compatibility should be restored without weakening stale-generation protection; documentation or a better error alone would leave previously working shipped callers broken.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • A broad automatic reclaim or adoption rule could defeat the fence that prevents an older physical session from clearing or overwriting its successor; the repair must distinguish legitimate sequential isolated calls from genuinely stale concurrent generations.
    • The report has a strong source-level reproduction, but a focused current-main execution has not yet confirmed the exact state transition and affected binding-identity variants.

    Codex review notes: model internal, reasoning high; reviewed against aaf5d23883a1.

    Label changes

    Label changes:

    • add P1: A regression in the latest release can stop established embedded Codex workflows after their first successful invocation.
    • add impact:session-state: The failure is caused by disagreement between logical session identity and the current physical Codex session generation.
    • add issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.
    • add clawsweeper:source-repro: Current issue advisory state selects this label.

    Label justifications:

    • P1: A regression in the latest release can stop established embedded Codex workflows after their first successful invocation.
    • impact:session-state: The failure is caused by disagreement between logical session identity and the current physical Codex session generation.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs extensions/codex/src/app-server/thread-lifecycle.binding.test.ts
    • node scripts/run-vitest.mjs extensions/codex/src/app-server/session-binding.test.ts
    • node scripts/run-vitest.mjs extensions/codex/src/app-server/run-attempt.test.ts
    • node scripts/check-changed.mjs -- extensions/codex/src/app-server/thread-lifecycle.ts extensions/codex/src/app-server/session-binding.ts extensions/codex/src/app-server/thread-lifecycle.binding.test.ts extensions/codex/src/app-server/session-binding.test.ts docs/plugins/sdk-runtime.md
    • git diff --check

    What I checked:

    Likely related people:

    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  3. self-assigned this
    on Jul 29, 2026
  4. steipete commented on Jul 29, 2026

    @steipete
    Contributor

    Fixed by #115601, merged as fed427a50ede2672f54bfc59ec85b4ecbda8a5fe.

    The fix resolves binding authority against the durable session row before Codex client startup. Current durable sessions keep stable-key generation fencing; mismatched or unreadable durable ownership fails closed; row-less ephemeral embedded runs bind their Codex state to the physical session ID, so a new physical run cannot inherit the previous ephemeral generation.

    Regression proof: starts sequential ephemeral generations that share a stable session key runs two sequential embedded Codex attempts with the same logical sessionKey and rotating sessionId values and proves both start independent native threads. The paired durable-mismatch regression proves a stale physical generation is rejected before client startup. The exact PR head passed the hosted CI gate before merge.

  5. locked as resolved and limited conversation to collaborators on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

Type

No type

Fields

Priority

None yet

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions