Skip to content

fix(gateway): preserve targetless media session ownership - #124111

Merged
steipete merged 1 commit into
mainfrom
fix/autoqa-refill-targetless-media-routing-v2
Aug 15, 2026
Merged

steipete merged 1 commit into
mainfrom
fix/autoqa-refill-targetless-media-routing-v2

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where an internally generated attachment recovered after a Gateway restart could be persisted through the wrong agent/session store when the durable delivery used a targetless global session key. Two agents can legally have the same literal key in separate stores, so re-deriving ownership from the key can misroute or lose the transcript attachment.

Why This Change Was Made

The restart sentinel already resolves the authoritative agentId, canonical key, and store path together when it loads the queued session. This change carries those resolved facts into generated-media transcript persistence and removes the later redundant agent re-resolution. It does not change delivery/replay behavior, routing, config, protocol, schema, retention, or security policy.

Production code is net +1 line: the new owner arguments are absorbed by deleting the redundant resolver path. Tests are net +90 lines. No changelog entry is needed because this is internal restart-recovery correctness with no public surface change.

User Impact

Targetless generated media recovered after restart now appears exactly once in the resolved owning agent's transcript. Another agent with the same global key remains untouched.

Evidence

  • Blacksmith Testbox: https://github.com/openclaw/openclaw/actions/runs/31874066179
  • pnpm build passed against the synchronized three-file source hashes.
  • Focused Gateway suite: 75/75 tests passed in src/gateway/server-restart-sentinel.test.ts.
  • Full changed gate passed: format, lint, core/test types, import cycles, media guard, database-first guard, native schema guard, runtime-sidecar guard, and boundary checks.
  • Built-Gateway restart proof used two agents with separate stores and the same targetless global key. The non-main ops owner received one stable attachment event; the main decoy received zero. The 68-byte attachment hash was 4b5c5c92cec3b23e6a294fc0eea43234ef5126c5a64f4c6c531ac8430ab0b844.
  • The durable session queue reached completed_permanent with retry count 0, no pending or failed rows, and no defer/advance/dead-letter metadata. A second Gateway start preserved the same event ID without duplication; both processes exited 0 and state/port cleanup passed.
  • Fresh Codex autoreview: clean, no actionable findings (0.99 confidence).

@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 15, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. 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 Aug 15, 2026
@clawsweeper

clawsweeper Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 15, 2026, 4:45 AM ET / 08:45 UTC.

ClawSweeper review

What this changes

The PR carries the agent and session-store ownership resolved during Gateway restart recovery into generated-media transcript persistence, preventing targetless global session keys from selecting another agent’s store.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open: the patch is a focused owner-boundary repair and no blocking correctness finding was identified. It remains maintainer-owned and should wait for its exact-head merge/CI state before landing.

Priority: P2
Reviewed head: 31923e0e13207cd0e4dbec0f59d7a4a700692f90

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with a meaningful real-store regression test and no identified correctness or security finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; its body nevertheless reports a built-Gateway restart proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; its body nevertheless reports a built-Gateway restart proof.
Evidence reviewed 5 items Current-main ownership mismatch: Current main resolves the owning agent and store with the queued session, but forwards only the canonical key to generated-media recovery; its transcript append then has to infer ownership again.
Transcript owner selection: For an unscoped key, the transcript writer selects an explicit agent if provided, otherwise derives from the key; global cannot encode the non-default owner selected by restart recovery.
Patch follows the authoritative facts: The PR passes the agent and store returned by session loading directly to the existing transcript writer, removing the redundant session-key resolver on the normal restart-turn path.
Findings None None.
Security None None.

How this fits together

Gateway restart recovery loads queued session work and resolves its canonical key, owning agent, and store before resuming generated-media delivery. That delivery records recovered attachments in the owning session transcript.

flowchart LR
  A[Queued media delivery] --> B[Restart recovery]
  B --> C[Resolve session owner]
  C --> D[Generated media delivery]
  D --> E[Transcript persistence]
  E --> F[Owning agent transcript]
Loading

Before merge

  • Resolve merge risk (P1) - The branch is marked behind and required checks are still in progress; confirm the clean merge result and exact-head CI before landing because this path writes durable session transcripts.
  • Complete next step (P2) - No repairable finding remains; the maintainer-owned protected PR needs its normal exact-head merge and CI gate.
Agent review details

Security

None.

PR surface

Source +1, Tests +90. Total +91 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 9 8 +1
Tests 1 95 5 +90
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 104 13 +91

Review metrics

Metric Value Why it matters
Production versus regression-test delta production +9/-8 (net +1); tests +95/-5 (net +90) The small production increase carries authoritative owner facts; the larger test change establishes the two-store persistence regression.

Merge-risk options

Maintainer options:

  1. Validate the exact merge result (recommended)
    Confirm a clean merge/rebase and green exact-head checks while retaining the two-agent targetless transcript regression before landing.

Technical review

Best possible solution:

Keep a single resolved owner tuple from restart-session loading through transcript persistence, retain the two-store global regression, and land only after the exact merge result is validated.

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

Yes in source: two agents with separate stores can share a targetless global key, while current-main transcript persistence re-derives rather than receives the selected owner. The submitted regression models that path, though it was not executed under the read-only review contract.

Is this the best way to solve the issue?

Yes. Propagating the owner tuple already chosen by restart recovery is narrower and safer than asking transcript persistence to infer ownership again from an ambiguous key.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded restart-recovery correctness repair that can mis-associate a recovered media transcript, without evidence of broad immediate outage.
  • add merge-risk: 🚨 session-state: The PR changes which persisted session store receives recovered generated-media transcript events.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; its body nevertheless reports a built-Gateway restart proof.

Label justifications:

  • P2: This is a bounded restart-recovery correctness repair that can mis-associate a recovered media transcript, without evidence of broad immediate outage.
  • merge-risk: 🚨 session-state: The PR changes which persisted session store receives recovered generated-media transcript events.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer-authored PR, so the external-contributor proof gate does not apply; its body nevertheless reports a built-Gateway restart proof.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame and shortlog identify Peter Steinberger as the author of the recent restart-sentinel path, and the same contributor authored this focused repair. (role: recent gateway/session ownership contributor; confidence: high; commits: f8fcc7f99b8a, 31923e0e1320; files: src/gateway/server-restart-sentinel.ts, src/gateway/server-restart-sentinel-agent-delivery.ts, src/config/sessions/transcript.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the exact-head required checks complete after confirming the merge result.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • 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.

@steipete
steipete merged commit de4104c into main Aug 15, 2026
193 checks passed
@steipete
steipete deleted the fix/autoqa-refill-targetless-media-routing-v2 branch August 15, 2026 08:50
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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