Skip to content

fix: chat.inject fails after a shared session entry is cached - #170137

Merged
steipete merged 8 commits into
openclaw:mainfrom
xyrolle:fix/transcript-target-cache-owner
Oct 15, 2026
Merged

steipete merged 8 commits into
openclaw:mainfrom
xyrolle:fix/transcript-target-cache-owner

Conversation

@xyrolle

@xyrolle xyrolle commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #170136
Refs #168677

What Problem This Solves

chat.inject fails with “Transcript session … is owned by …” after a cron base row is cached when its isolated :run:<sessionId> row owns their shared transcript.

User Impact

Injected notes reach the transcript owner whether or not the requested row was cached. No configuration change, migration, or protocol change is required.

Why This Change Was Made

The shortcut introduced in 3bbc221d1c8c (#168677) treated a matching cached entry session ID as proof of transcript ownership. Base and run rows can share that ID; session_windows.session_key identifies the owner. Removing the shortcut uses the existing admitted worker lookup, preserves the transactional ownership checks and post-await authority checks, and removes 22 production lines. Formerly cached durable targets now require one worker lookup. Memory-backed behavior is unchanged, and there is no new cache, schema, main-thread SQL, or detached/background effect.

The prior PR CI's fourteen sessions-goal.test.ts failures exposed a separate fixture leak. The preceding steering test created a second tool-authority snapshot for the shared-secret owner and released only its operator authority. Fingerprinting retains an entry predicate owned by the tool snapshot; its close() was missing. The fixture now closes that snapshot in finally and checks zero retained facts after its own cleanup. The existing “Completed handlers must release retained session sharing facts” assertion and production accounting are unchanged.

Original fix by @xyrolle (Serghei); this maintainer implementation preserves contributor credit and history. The separate typed-refusal work in #170176 remains outside this fix.

Evidence

PR CI is the test gate per maintainer policy. It covers Gateway/config regressions and sibling suites, typechecks, lint, build, and repository checks. Exact head eb5892da0815e91de8520866372ff24611bb8f7c passed CI run 38706420593: 81 checks succeeded, 28 skipped, zero failures, on the first attempt. All typecheck and lint checks passed; no inherited-failure exception or CI rerun was needed.

Exact-head test results, recovered from the cached completed-run archive:

Test file Passed Relevant CI result Job
sessions-goal.test.ts 14/14 All prior retained-fact failures are green 116327657810
chat-send-steering-custody.test.ts 18/18 Existing shared-secret owner case with cleanup assertion: 6.506 s 116327657810
session-accessor.transcript-identity.test.ts 19/19 Cached shared-ID owner regression: 92 ms 116327658357
server.sessions.store-rpc.test.ts 6/6 Cached base/run double-injection regression: 1.121 s 116327657462

Times above are individual CI case times, not isolated-file wall times. The new cases reuse existing fixtures and add no timer, sleep, or polling. The latest ClawSweeper review (comment 6130947649, reviewed head 3fb78b2737bf) has no code findings and reports complete fix scope; it has not reviewed this new head. No new code finding was present at closeout. PR CI supplies the proof under maintainer policy.

Regression coverage:

  • resolves a shared session ID to its transcript owner after the requested row's facts are retained checks both owner key and owner lifecycle revision. Existing across-entry-write revision assertions remain; only the read-count expectation requiring the broken shortcut is removed.
  • chat.inject writes to the transcript owner after the requested row's facts are cached uses the base/run key shape, warms the base row with sessions.abort, injects twice, and checks exactly the ordered assistant notes in the owner's transcript.
  • preserves authenticated chat.send steering authority across callers (shared-secret owner) now checks zero retained sharing facts at the leaking fixture's boundary; existing Goal cleanup assertions remain intact.

Source/history confirmation used git log -p -S 'const current = sessionKey' and the real chat.inject → transcript resolver → transactional writer path. Prior CI log 38693348811 / 116284566103 shows a fixed retained count of one in all fourteen Goal cases, with the steering suite completing immediately beforehand.

Changed-file oxfmt --check passed (344 ms, five files). Both node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json and direct oxlint on the four changed TypeScript files exited 0. Deslop is complete. Precommit and prescribed committed-branch Codex autoreview are both scoped-clean at P0–P2 with no actionable findings. The final main merge left the five patch files and reviewed lifetime owners byte-identical to the branch-reviewed candidate; git diff --check passed. The installed canonical helper is used because the repository launcher is absent, retaining isolation and the requested engine/priority settings. Local unit/module tests, typechecks, negative controls, and live Gateway proof were intentionally skipped per maintainer policy. No Crabbox/Testbox lease was created. Test execution times come from CI; no local runtime measurement is claimed.

Area Added Removed Net
Production 1 23 -22
Tests 69 23 +46
Docs 1 1 0

resolveSessionTranscriptRuntimeTarget returned the requested key whenever
a retained entry row named the requested session ID. That does not prove
transcript ownership: an isolated cron run's row is written after its base
row and owns the shared transcript. After sessions.abort retained the base
row's facts, chat.inject on the base key hit the ownership check on every
attempt, while the uncached path wrote to the owner.

Retained facts carry no window owner, so drop the cached branch and always
read the persisted session-ID index, as the uncached path does. Each
resolution that used the cached branch now costs one runtime-target worker
request (one SQL statement, 1.2 when qualified); measured locally that is
about 0.5-1.8 ms at p50 per resolution, and the gateway concurrency
benchmark shows no difference beyond its noise. Publishing a proven
owner from actor state and write postimages would keep the cached branch
for those sources.

Proof: a Gateway WebSocket regression (sessions.abort, then two
chat.inject calls) and a resolver case for the shared session ID fail on
main and pass with the fix. The openclaw#168677 pin keeps its behavioral checks
(current transcript and lifecycle revision) without a read-count bound.

Refs openclaw#168677
@clawsweeper

clawsweeper Bot commented Oct 12, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-12T19:12:13.202692Z 3fb78b2 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR resolves cached transcript targets through their persisted owner and closes a leaking test authority snapshot.

Example: After sessions.abort caches agent:main:cron:job, inject "first" and "second" while agent:main:cron:job:run:selected-window owns the shared transcript.

  • Before: Both injections fail with a transcript ownership error.
  • After: Both notes append in order to the run owner's transcript.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch appears correct and has successful CI, but the required shipped-entry-point evidence cannot currently be inspected.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Injected notes repeatedly fail after a requested session row is cached when another key owns its shared transcript.
Reason: The focused repair restores cache-independent behavior, preserves the established ownership contract, and introduces no new public surface.

Regression provenance

Regression provenance — suspected predecessor, not a causality claim: source commit ca77256127e6 by Peter Steinberger; no PR verified.

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this PR fixes a deterministic transcript-owner regression still present on current main, and the reviewed diff introduces no actionable code findings.

Priority: P1
Reviewed head: eb5892da0815e91de8520866372ff24611bb8f7c

Before merge

  • Add real behavior proof - The changed durable-target resolver is exercised by Gateway WebSocket regression tests and successful exact-head CI. An earlier review accepted built-Gateway CLI output, but its underlying evidence is no longer available in the current body or discussion. Restore that existing redacted output, or supply equivalent Gateway output showing sessions.abort warming the base row, both injections succeeding, and chat.history returning both notes from the owner; redact IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: Restore the previously supplied built-Gateway trace showing cache warming, two successful injections, and owner history readback; the current evidence also does not show the new cases failing on the base.
Agent review details

How this fits together

Gateway transcript writers submit session identities to the shared resolver, which selects the physical transcript owner before transactional append checks.

flowchart TD
A[Gateway chat.inject] --> B[Transcript turn persistence]
B --> C[Runtime target resolver]
C --> D[Admitted session read worker]
D --> E[Persisted window owner]
E --> F[Transactional ownership check]
F --> G[Transcript append]
Loading

Technical review

Best possible solution:

Use the existing persisted-window owner lookup for durable transcript targets while retaining transactional ownership checks.

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

The linked report's shared-ID fixture and Gateway failure frames match the current-main cache shortcut and transactional rejection; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Removing the unsupported shortcut restores the established owner contract with less complexity than introducing cached ownership facts and another invalidation lifecycle.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 86380bba721a.

Provenance checked

  • Retained-entry runtime target shortcut changes intended behavior with a stated reason (3bbc221: Reduce warm transcript-target worker reads while preserving session behavior.)
  • Durable transcript ownership keeps the original intent (de291a3: Resolve transcript writes through the persisted window owner and reject ownership changes transactionally.)
  • Shared-secret steering authority test keeps the original intent (13f1d5b: Verify shared-secret owners can steer across devices while preserving existing authority restrictions.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source -22, Tests +46, Docs 0. Total +24 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 1 23 -22
Tests 3 69 23 +46
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 71 47 +24

Review metrics

Metric Value Why it matters
Production versus test changes Production +1/-23; tests +69/-23 Production shrinks by removing the incorrect shortcut; tests cover owner lifecycle identity, Gateway injection ordering, and fixture cleanup.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • remove proof: sufficient: Current real behavior proof status is insufficient, not sufficient.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P1: A deterministic current-main regression repeatedly refuses transcript injection for affected cron sessions after their entry facts are cached.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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 execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-12T19:14:50.581Z sha 3fb78b2 :: needs real behavior proof before merge. :: none
  • reviewed 2026-10-13T08:30:09.095Z sha 3fb78b2 :: needs maintainer review before merge. :: none

Reviewed October 15, 2026, 5:08 AM ET / 09:08 UTC (Revision 3).

@xyrolle

xyrolle commented Oct 13, 2026

Copy link
Copy Markdown
Contributor Author

CI triage for run 38295714460 (19 failing checks-node-changed-* jobs, 48 failing files). This PR changes one function, resolveSessionTranscriptRuntimeTarget. To separate its effect, I worked on this branch merged with main 5b1031a10. All 17 files in the table below ran with this PR's resolver, and the 13 that failed ran again with session-accessor.transcript-target.ts restored to main's version. I also compared the whole core-runtime-config-hosted-7 shard and the finalization-scope suite, described next. CI merged with ddaf75ff.

31 files fail only on the prepared-config contract from #169714. Each failing case in them either throws Runtime config is not prepared. Await captureRuntimeConfigAsyncReader()() first. or is an assertion that received that error. Main is repairing fixtures broken this way one file at a time, for example #170227 (open), d7be702 and 4001f37. None of those touches these 31 files yet. I ran one whole shard locally, core-runtime-config-hosted-7: 24 files, of which 8 failed with 32 failing cases and 16 passed. It fails identically with either resolver. embedded-agent-runner.run-embedded-agent.finalization-scope.test.ts from this group also fails the same 8 cases with either resolver.

The other 17 files.

File This PR's resolver Main's resolver
src/config/sessions/session-accessor.test.ts 1 failed ("…session id rotates mid-append": rejectedReason undefined) same 1 failed
src/agents/embedded-agent-runner/run/settled-turn-finalization.unavailable.test.ts 1 failed (assistantTranscriptOwned undefined) same 1 failed
src/agents/embedded-agent-runner/run-orchestrator.suspension.test.ts 21 failed (runtime config) same 21 failed
src/agents/tools/message-tool.internal-source-reply.integration.test.ts 9 failed (runtime config) same 9 failed
src/auto-reply/reply/queue.pending-inputs.test.ts 2 failed (runtime config) same 2 failed
src/sessions/session-state-events.ownership.test.ts 3 failed (one is the #169714 message) same 3 failed, same assertions
src/agents/tools/media-generate-background-retention.test.ts 14 failed: 8 null assertions (null == true, expected null to match object) and 6 timeouts at 120 s same 14 failed, same assertions and timeouts
test/e2e/qa-lab/runtime/gateway-heartbeat-session-routing.e2e.test.ts 1 failed ("Originally observed agent target requires its captured creating reference") same failure
src/gateway/gateway-workshop-learning.e2e.test.ts 1 failed (skill_workshop review results) same failure
test/e2e/qa-lab/runtime/channel-progress-presentation.e2e.test.ts 1 failed, 15 passed ("timed out waiting for progress finalization") same failure
src/config/sessions/session-accessor.pending-inputs.test.ts 1 failed (runtime config). CI also had a database is locked failure in "stages repeated relocation through savepoints…"; it did not reproduce locally with either resolver same 1 failed
src/config/sessions/session-accessor.transcript-turn-initialization.test.ts 9 failed (runtime config, plus "Commit settled before both callbacks accepted work") same 9 failed, same messages
src/infra/heartbeat-runner.webchat-exec-completion.test.ts 2 failed (runtime config) same 2 failed
src/auto-reply/reply/session.test.ts passes 87/87 (CI: database is locked) n/a
src/config/sessions/session-accessor.sqlite-transcript-parent.test.ts passes 14/14 (CI: database is locked) n/a
src/gateway/server-methods/sessions-create-thinking-claim.test.ts passes 3/3 n/a
src/commands/doctor-config-preflight.test.ts passes 17/17 n/a

Summary: 13 of these 17 files fail locally with either resolver, with the same cases and messages. The 4 that pass locally (two of them failed in CI with database is locked) were not run with main's resolver, so their CI failures did not reproduce and stay unattributed. None of the comparisons showed a failure that depends on the resolver. ci-gate aggregates the jobs above.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 13, 2026
Merge current main, retain the authoritative worker lookup, strengthen injected-message and owner-lifecycle regressions, and document shared-transcript behavior. Fixes openclaw#170136.

Co-authored-by: Serghei <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added the docs Improvements or additions to documentation label Oct 15, 2026
steipete and others added 6 commits October 14, 2026 23:30
Resolve durable transcript targets through the admitted owner lookup when
cron base/run rows share a session ID. Preserve owner lifecycle revisions
and cover two ordered chat.inject calls after sessions.abort warms the row.

Close the steering fixture's extra tool-authority snapshot, which retains
one entry predicate and polluted the following Goal cleanup assertions.
Check zero retained facts at the originating fixture without changing the
production accounting or existing Goal assertion.

Fixes openclaw#170136

Co-authored-by: Serghei <[email protected]>
Preserve the original PR ancestry while retaining the independently reimplemented and reviewed maintainer tree. No source changes in this merge.
@steipete steipete changed the title fix(sessions): cached transcript targets ignore ownership, so writes to a shared-session cron key are refused fix: chat.inject fails after a shared session entry is cached Oct 15, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 15, 2026
@steipete
steipete merged commit b4b89d4 into openclaw:main Oct 15, 2026
186 of 187 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 16, 2026
…aw#170137)

* fix(sessions): resolve cached transcript targets through their owner

resolveSessionTranscriptRuntimeTarget returned the requested key whenever
a retained entry row named the requested session ID. That does not prove
transcript ownership: an isolated cron run's row is written after its base
row and owns the shared transcript. After sessions.abort retained the base
row's facts, chat.inject on the base key hit the ownership check on every
attempt, while the uncached path wrote to the owner.

Retained facts carry no window owner, so drop the cached branch and always
read the persisted session-ID index, as the uncached path does. Each
resolution that used the cached branch now costs one runtime-target worker
request (one SQL statement, 1.2 when qualified); measured locally that is
about 0.5-1.8 ms at p50 per resolution, and the gateway concurrency
benchmark shows no difference beyond its noise. Publishing a proven
owner from actor state and write postimages would keep the cached branch
for those sources.

Proof: a Gateway WebSocket regression (sessions.abort, then two
chat.inject calls) and a resolver case for the shared session ID fail on
main and pass with the fix. The openclaw#168677 pin keeps its behavioral checks
(current transcript and lifecycle revision) without a read-count bound.

Refs openclaw#168677

* fix(sessions): preserve transcript ownership after cached entry reads

Resolve durable transcript targets through the admitted owner lookup when
cron base/run rows share a session ID. Preserve owner lifecycle revisions
and cover two ordered chat.inject calls after sessions.abort warms the row.

Close the steering fixture's extra tool-authority snapshot, which retains
one entry predicate and polluted the following Goal cleanup assertions.
Check zero retained facts at the originating fixture without changing the
production accounting or existing Goal assertion.

Fixes openclaw#170136

Co-authored-by: Serghei <[email protected]>

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Serghei <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: chat.inject is refused with "is owned by" once a session's entry facts are cached and another key owns its transcript

2 participants