Skip to content

fix(agents): avoid false subagent completion on case-colliding sessions - #122142

Closed
Alix-007 wants to merge 4 commits into
openclaw:mainfrom
Alix-007:alix/fix-122047-session-key-collision
Closed

Alix-007 wants to merge 4 commits into
openclaw:mainfrom
Alix-007:alix/fix-122047-session-key-collision

Conversation

@Alix-007

@Alix-007 Alix-007 commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #122047

Thanks to @yunligou711-commits for the report.

What Problem This Solves

Fixes an issue where users running subagents with case-sensitive Matrix room or Signal group identifiers could have reconciliation infer completion from a different case-colliding sibling session.

Why This Change Was Made

Reconciliation now performs the exact lookup first and then uses the existing canonical store-key normalizer. This keeps structural session-key segments case-insensitive while preserving opaque peer identifiers, without introducing a legacy alias or delivery-metadata fallback.

User Impact

Subagent completion is now attributed only to the intended session when opaque peer identifiers differ by case. Existing session keys that differ only in structural segment casing continue to reconcile normally.

Evidence

Current exact-head production-path SQLite sweeper proof on Node 24.18.0:

The downloaded artifact records these machine verdicts through production agent-session SQLite accessors, shared registry SQLite persistence/reload, and the production sweeper:

  • Matrix collision: 2 agent-session rows and 1 registry row produced only sweeper-lost-context / error, with no false completion.
  • Signal collision: 2 agent-session rows and 1 registry row produced only sweeper-lost-context / error, with no false completion.
  • Structural-key control: 1 agent-session row and 1 registry row still produced sweeper-session-completion / ok.

Immutable parent-red evidence remains in the earlier run:

That artifact used the same production-path harness to show Matrix and Signal case-colliding peers incorrectly producing sweeper-session-completion / ok before the repair. It also recorded the repaired owner source at the previous PR head; the current-head artifact above supersedes that after-fix half.

Current-head focused verification on Node 24.15.0:

node scripts/run-vitest.mjs \
  src/agents/subagents/registry/subagent-session-reconciliation.test.ts \
  src/sessions/session-key-case-preservation.test.ts \
  --reporter=verbose
Test Files  2 passed (2)
Tests       45 passed (45)

node scripts/check-changed.mjs -- \
  src/agents/subagents/registry/subagent-session-reconciliation.ts \
  src/agents/subagents/registry/subagent-session-reconciliation.test.ts
passed

git diff --check
passed

The changed gate covered max-lines, SDK/API and boundary guards, dead-code checks, production and test tsgo, lint, database-first/sidecar guards, import cycles, and auth/guard checks. Crabbox had no ready provider, so the trusted-source wrapper used its documented local fallback.

Scope and risk:

  • Production: +2/-11 (net -9).
  • Tests: +60/-0.
  • No config, schema, migration, dependency, SDK, public API, security, provider, or protocol change.

@clawsweeper

clawsweeper Bot commented Aug 11, 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 agents Agent runtime and tooling size: S labels Aug 11, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 23, 2026, 8:24 PM ET / August 24, 2026, 00:24 UTC.

ClawSweeper review

What this changes

This PR replaces broad lowercased subagent session-key matching with canonical store-key lookup and adds Matrix, Signal, and structural-key regression coverage.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this PR open. PR close coverage proof kept this PR open against #127279: model PR close coverage proof was incomplete: PR B directly carries PR A's concrete bug fix and invariant into the merged canonical implementation; no material source behavior remains independently reviewable on PR A.

Priority: P1
Reviewed head: 7f92e90240e4c7c2d912c4f62838452a530de6e0

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The patch and its evidence are strong, but the work is already represented by the merged canonical replacement.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (linked_artifact): The PR body supplies linked exact-head production-path SQLite before/after artifacts for both collision cases and the structural control.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (linked_artifact): The PR body supplies linked exact-head production-path SQLite before/after artifacts for both collision cases and the structural control.
Evidence reviewed 5 items PR close coverage proof: PR close coverage proof kept this PR open against #127279: model PR close coverage proof was incomplete: PR B directly carries PR A's concrete bug fix and invariant into the merged canonical implementation; no material source behavior remains independently reviewable on PR A.
Current-main implementation: Current main performs an exact lookup followed by the shared canonical normalizer, rather than scanning every lowercased key.
Current-main regression coverage: The same focused tests cover structural casing plus Matrix and Signal opaque-peer collisions.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/subagents/registry/subagent-session-reconciliation.test.ts --reporter=verbose

Result: FAIL (failed) — execution before step 1 run: live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

live-proof package manager pnpm is unavailable after its official installer (curl -fsSL https://get.pnpm.io/install.sh | sh -): command failed without output

Assertions:

  • FAIL expect_output: does not match a case-distinct Matrix opaque peer
  • FAIL expect_output: 3 passed

How this fits together

Subagent reconciliation reads persisted child-session records to decide whether a parent agent receives a completion outcome. Session-key normalization must preserve opaque peer identifiers while normalizing structural routing segments.

flowchart LR
  Child[Child session key] --> Reconcile[Subagent reconciliation]
  Store[Persisted session entries] --> Reconcile
  Reconcile --> Normalize[Canonical key normalization]
  Normalize --> Match[Matched child entry]
  Match --> Outcome[Parent completion outcome]
Loading

Before merge

  • Complete next step (P2) - No repair lane is needed because the merged canonical PR already owns this implementation.
Agent review details

Security

None.

PR surface

Source -9, Tests +60. Total +51 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 11 -9
Tests 1 60 0 +60
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 62 11 +51

Review metrics

Metric Value Why it matters
Production vs regression tests production +2/-11 (net -9); tests +60/-0 The repair removes the broad fallback scan while adding focused coverage for the preserved session-key invariant.

Technical review

Best possible solution:

Keep this PR open until a linked canonical PR proves it covers this PR's unique work, or a maintainer confirms closure.

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

Yes, source reproduction is high-confidence: current-main regression cases construct Matrix and Signal keys that differ only in opaque-peer casing and assert no completion is inferred.

Is this the best way to solve the issue?

Yes. The merged replacement uses the shared session-key normalizer at the lookup owner, preserving structural normalization without broad opaque-peer folding; this branch adds no remaining unique solution.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a3f64c19b673; fix evidence: commit fcc0bb74900b, main fix timestamp 2026-08-22T02:41:42Z.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove merge-risk: 🚨 session-state: Current PR review selected no merge-risk labels.

Label justifications:

  • P1: The repaired behavior could otherwise terminalize a parent subagent from a case-distinct sibling session.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (linked_artifact): The PR body supplies linked exact-head production-path SQLite before/after artifacts for both collision cases and the structural control.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies linked exact-head production-path SQLite before/after artifacts for both collision cases and the structural control.

Evidence

What I checked:

Likely related people:

  • obviyus: Authored the merged replacement that now owns the canonical lookup and regression coverage on current main. (role: merged canonical repair author; confidence: high; commits: fcc0bb74900b; files: src/agents/subagents/registry/subagent-session-reconciliation.ts, src/agents/subagents/registry/subagent-session-reconciliation.test.ts)
  • Alix-007: The merged replacement credits this PR’s root-cause work and regression coverage as source material. (role: source contributor; confidence: medium; commits: 7f92e90240e4; files: src/agents/subagents/registry/subagent-session-reconciliation.ts, src/agents/subagents/registry/subagent-session-reconciliation.test.ts)

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.

History

Review history (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-11T21:58:52.291Z sha 7f92e90 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-11T22:59:20.255Z sha 7f92e90 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T00:58:32.739Z sha 7f92e90 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T18:52:01.780Z sha 7f92e90 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T20:46:24.115Z sha 7f92e90 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-16T20:41:51.859Z sha 7f92e90 :: needs maintainer review before merge. :: none
  • reviewed August 16, 2026, 6:42 PM ET / 22:42 UTC sha unknown :: needs maintainer review before merge. :: none
  • reviewed 2026-08-18T12:19:24.685Z sha 7f92e90 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 11, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 11, 2026

@atomicdjt atomicdjt left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source-level cross-check against current main (8f59226bc93a): the canonical-normalizer shape in this PR looks preferable to an exact-only lookup for one additional reason beyond the reported Matrix/Signal collision.

registerPluginSubagentRunFromGateway() currently only trim()s the plugin-supplied childSessionKey before persisting the registry row; it does not canonicalize structural segments. Meanwhile the session-store owner canonicalizes keys through the shared session-key normalization path, and listSessionEntriesReadOnly() asserts canonical persisted keys. That means an exact-only reconciliation lookup can create a semantic split: a structurally equivalent key such as an uppercase Agent:MAIN:... variant can name the same canonical stored session but fail only in reconciliation.

Using normalizeStoreSessionKey(sessionKey) after the exact probe avoids that split while still preserving the actual safety property here: Matrix room tails and Signal group IDs remain opaque/case-sensitive because the shared normalizer explicitly preserves those spans. So the desired contract is not “all bytes exact”; it is canonical structural identity + exact opaque peer identity.

The current tests already exercise the three important points well:

  • structural casing still resolves;
  • Matrix case-distinct peers do not resolve each other;
  • Signal case-distinct peers do not resolve each other.

If you want one final regression lock before merge, I would add/retain a parity assertion that the reconciliation cache path uses the same canonical identity as the session-store owner, while never invoking the folded legacy-alias fallback. Not a blocker given the production-path artifacts already in the PR, but it would document why the normalizer is intentional rather than merely a smaller lowercase scan.

Nice repair shape overall: it removes the unsafe global case-fold scan without throwing away the repository's existing canonical-key contract.

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 15, 2026
@Alix-007

Copy link
Copy Markdown
Contributor Author

Thanks @atomicdjt for the careful cross-check. I agree with the framing: the invariant here is canonical structural identity plus exact opaque peer identity, not byte-exact lookup. The current structural, Matrix, and Signal regressions are intended to lock that boundary, and reconciliation stays on the shared canonical normalizer without reviving the folded legacy-alias scan. I appreciate the parity-test suggestion as a useful non-blocking follow-up.

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 24, 2026
@steipete

Copy link
Copy Markdown
Contributor

Already fixed on main by #127279 (fcc0bb7). The merged change contains the same canonical session-key lookup and Matrix/Signal collision regression tests, and preserves @Alix-007 contributor credit. Thank you!

@steipete steipete closed this Aug 24, 2026
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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor 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.

[Bug]: Subagent reconciliation can infer completion from a case-colliding sibling session

3 participants