Skip to content

fix(agents): reread native ownership when the writer claim follows admission - #169101

Merged
RomneyDa merged 1 commit into
mainfrom
fix/native-ownership-admitted-writer
Oct 11, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
fix/native-ownership-admitted-writer

Conversation

@RomneyDa

Copy link
Copy Markdown
Member

What Problem This Solves

Since #168992 (e63b5a0), every run on a session pinned to a native harness with session-runtime ownership (Codex) fails before dispatch whenever the lane has claimed the session writer:

AgentHarnessPreflightError: Native model ownership changed during run preparation. Reattach the original native session before retrying.

Current main (0690a2ef) fails 5/10 tests in src/agents/embedded-agent-runner/run.harness-auth-failover.test.ts for this reason. That test file blocks CI for any PR that touches the embedded runner, for example #168401.

Why This Change Was Made

Root cause:

  • perf(agents): reduce repeated SQLite work during agent preparation #168992 reused the run-admission session snapshot (sessionAdmission.entry) for the first native ownership read in prepareNativeSessionRuntime (src/agents/embedded-agent-runner/run/model-setup.ts).
  • Admission runs in prepareEmbeddedRunSession. The lane controller claims the session writer later, in claimAgentSessionWriter in lane-controller.ts, and then sets sessionTarget.expectedWriterRunId.
  • So the admitted snapshot never carries the claimed activeWriterRunId, and the ownership assertCurrent writer check always fails.
  • I confirmed this by instrumenting the check: expectedWriter: "run-1", activeWriterRunId: undefined, all other fields matching.

Fix: reuse the admitted snapshot only when it already carries the expected writer, or when there is no writer claim. Otherwise take the existing worker read, which is the behavior before #168992. The no-claim reuse that #168992 added (and its no-main-thread-SQL test) is unchanged.

Alternative considered: patching the claimed writer into the admitted snapshot, or refreshing admission inside the lane claim. Both would fabricate or relocate row state across owners. Rereading is the existing authoritative path.

User Impact

Pinned native Codex sessions run again instead of failing every turn at preparation. There is no config or schema change.

Evidence

  • git bisect between bdcbb2d (good) and ff6f58a (bad), running run.harness-auth-failover.test.ts, names e63b5a0 as the first bad commit.
  • New regression test, model-setup.ownership.test.ts "rereads native ownership when the writer claim follows run admission". It fails on main with the exact error above and passes with this fix.
  • pnpm test src/agents/embedded-agent-runner/run/model-setup.ownership.test.ts src/agents/embedded-agent-runner/run.harness-auth-failover.test.ts: 42/42 pass. The 10 failover tests were 5/10 on main.
  • Production LOC: +7/-1.

Note: node scripts/check-changed.mjs currently stops at duplicate scan target coverage because of the root worker-heap-flag.mjs added in #166581. That failure also happens on main and is unrelated to this change.

…mission

#168992 (e63b5a0) reused the run-admission session snapshot for the first
native ownership read. Admission runs in prepareEmbeddedRunSession, before
the lane controller claims the session writer, so the snapshot never carries
the claimed activeWriterRunId. Every pinned native harness run with a writer
claim then failed with "Native model ownership changed during run
preparation" (run.harness-auth-failover.test.ts, 5 tests).

Reuse the admitted snapshot only when it already carries the expected writer;
otherwise take the existing worker read.
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@RomneyDa
RomneyDa marked this pull request as ready for review October 11, 2026 12:38
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Oct 11, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR rereads native session ownership when the admission snapshot does not contain the subsequently claimed writer.

Example: Session agent:main:model-chat is admitted before its writer becomes claimed-writer.

  • Before: Preparation compares claimed-writer with the snapshot's missing activeWriterRunId and throws AgentHarnessPreflightError.
  • After: Preparation reads the current session row, verifies claimed-writer, and retains native ownership.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with useful regression coverage; supplied behavioral evidence remains an in-process harness rather than a shipped-entry-point run.
Proof confidence 🦐 gold shrimp (3/6) This MEMBER-authored PR is outside the ordinary contributor proof gate; supplied evidence reports production-owner harness tests, while no live Gateway/Codex turn is shown and no new authority boundary is introduced.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A pinned native session fails during model preparation after the lane claims its writer.
Reason: This maintainer-authored repair restores the existing workflow with a narrow change and preserves the original optimization where its snapshot remains usable.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR repairs a current-main regression that rejects pinned native sessions after writer admission. No actionable introduced defect was found.

Priority: P1
Reviewed head: 4699044ab635f8a1a63978f672b3e45f00f6293b

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not show an actual pinned native-session turn reaching Codex dispatch through a shipped Gateway.
Agent review details

How this fits together

The embedded runner admits a session, claims its writer through the lane controller, prepares native model ownership, and validates that ownership before harness dispatch.

flowchart TD
  A[Session admission] --> B[Lane writer claim]
  B --> C[Native model preparation]
  C --> D[Snapshot matches writer]
  D --> E[Reuse admitted row]
  D --> F[Read current row through owner]
  E --> G[Ownership validation and dispatch]
  F --> G
Loading

Technical review

Best possible solution:

Retain the conditional authoritative reread while preserving snapshot reuse and existing dispatch validation.

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

The production ordering deterministically supplies a pre-claim row to a post-claim writer check on current main; the author reports matching baseline failures and a passing regression, but no tests were executed during this read-only review.

Is this the best way to solve the issue?

The conditional reread repairs the stale input at the existing ownership boundary without fabricating row state, moving writer responsibility, or weakening validation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3a0db8a3a052.

Provenance checked

  • Initial native ownership read changes intended behavior with a stated reason (e63b5a0: Reuse admitted session facts to reduce repeated SQLite work while retaining ownership validation at dispatch.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e63b5a0 adds src/agents/embedded-agent-runner/run/model-setup.ts:81 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e63b5a01cf26; files: src/agents/embedded-agent-runner/run/model-setup.ts)
  • Ayaan Zaidi: Raw commit e1b01f7 adds src/agents/embedded-agent-runner/run/model-setup.ts:421 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: e1b01f779ddd; files: src/agents/embedded-agent-runner/run/model-setup.ts)

PR surface

Source +6, Tests +15. Total +21 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 7 1 +6
Tests 1 15 0 +15
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 22 1 +21

Review metrics

Metric Value Why it matters
Production versus test LOC Production +7/-1; tests +15/-0 The small conditional restores an existing read path, and the focused regression covers admission-before-claim ordering.

Labels

Label changes:

  • add P1: Current-main preparation rejects pinned native sessions with a subsequently claimed writer, blocking the affected agent workflow before dispatch.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: Current-main preparation rejects pinned native sessions with a subsequently claimed writer, blocking the affected agent workflow before dispatch.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 11, 2026, 8:44 AM ET / 12:44 UTC.

@RomneyDa
RomneyDa merged commit 3258dd8 into main Oct 11, 2026
239 of 249 checks passed
@RomneyDa
RomneyDa deleted the fix/native-ownership-admitted-writer branch October 11, 2026 13:09
@RomneyDa

Copy link
Copy Markdown
Member Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…mission (openclaw#169101)

openclaw#168992 (70e895e) reused the run-admission session snapshot for the first
native ownership read. Admission runs in prepareEmbeddedRunSession, before
the lane controller claims the session writer, so the snapshot never carries
the claimed activeWriterRunId. Every pinned native harness run with a writer
claim then failed with "Native model ownership changed during run
preparation" (run.harness-auth-failover.test.ts, 5 tests).

Reuse the admitted snapshot only when it already carries the expected writer;
otherwise take the existing worker read.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant