Skip to content

fix: watched-session changes invalidate conversation request prefixes - #182354

Merged
steipete merged 3 commits into
openclaw:mainfrom
ensignwesley:fix/watched-session-turn-context
Oct 26, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
ensignwesley:fix/watched-session-turn-context

Conversation

@ensignwesley

@ensignwesley ensignwesley commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Related: #114797

What Problem This Solves

Adding, renaming, or removing watched groups changes the system-prompt suffix ahead of existing conversation history on compatible provider routes. That invalidates an otherwise reusable request prefix.

User Impact

Watched-group awareness stays current without rewriting earlier model context. Existing same-agent, main-session, read-tool, sandbox, and full-prompt visibility checks remain in force. No configuration or migration is required.

Why This Change Was Made

Carry the watch owner's admitted snapshot in the existing current-turn runtime context, including an explicit empty snapshot after the last readable watch disappears. Tool-context refresh accepts the refreshed snapshot without putting it back into the system prompt. The released synchronous SDK and separate compaction prompt keep their existing contracts.

The simplification pass retained one watch preparer and one existing runtime-context carrier. Production is +50/-12 (net +38), tests +81/-0, and documentation +5/-0. The remaining growth carries the snapshot and its empty state through those existing owners; no new cache, registry, or persistence owner is introduced.

Thanks @ensignwesley for the original repair and regression.

Evidence

  • Published head: 1c9cdc778592bb53866ec3b092c794f571f0b3c3; contributor commits remain intact.

  • Fresh negative control: the added regression fails against unchanged main production at d649e04268584642e16c1775e2e05556b8014ca3, specifically because the watched title appears in the system prompt. The failing case took 7.692 s; the cold command took 318.79 s.

  • Fresh candidate verification: the four exact changed TypeScript blobs from this head passed all 50 tests across prompt preparation, watched sessions, and agent-tools.prefix-stability.test.ts in the same tooling checkout. The regression took 5.193 s; total command wall time was 377.17 s, mostly compilation/runner startup. Targeted oxlint and oxfmt passed. These local checks used the tooling checkout's surrounding main code; exact-head CI supplies whole-revision proof.

  • Exact-head CI run 40279901199 passed, including openclaw/ci-gate; the published security/dependency gate also passed.

  • Prior source-Gateway HTTP proof at 8dbbbf71e18e3dcc71bb6c9c1c45d2fd89788ec2 exercised empty → add → cold reopen/rename → removal across two isolated Gateway processes. System/tool bytes and previous message prefixes stayed identical, current watch facts reached each new turn, and removal supplied an empty snapshot. The three production owners are byte-identical to this head, verified again during this review.

  • That prior integration also recorded a local Qwen2.5 7B/Ollama control, a full build, targeted types, and pnpm prompt:snapshots:gen with zero generated delta. These are retained prior-head results, not newly rerun claims.

  • Fresh independent Codex review completed with a validated scoped-clean result at P0–P2; no actionable findings. Documentation formatting and a conflict-free merge-tree check against current main also passed.

No fresh live Gateway or external-provider run was performed in this pass: the recorded transport proof covers unchanged production bytes, and the fresh checks target the owning regression. No inbound chat.send, real channel round-trip, cache-hit-rate, or latency claim is made.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Oct 24, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Moves watched-session membership and titles from the embedded system prompt into the current turn’s runtime context.

Example: Rename watched group agent:main:telegram:group:fixture from Original room to Renamed room.

  • Before: The renamed title changes the system prompt ahead of existing conversation history.
  • After: The new turn carries Renamed room while the system prompt and earlier snapshots remain unchanged.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused repair with reusable Gateway evidence, a meaningful owner regression, passing exact-head gates, and no actionable finding.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Recorded source-Gateway HTTP proof exercises the embedded watch owner across empty, add, cold reopen/rename, and removal, preserving prior request prefixes while delivering current facts; production files match that proof head, and the retained review records inspection of its captures.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Adding, renaming, or removing watched groups can invalidate an otherwise reusable conversation request prefix.
Reason: Restores the documented stable-context invariant while keeping current watch awareness and existing visibility rules.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: current main still has the prompt-prefix defect, and this focused repair preserves access checks without introducing an actionable bug.

Priority: P2
Reviewed head: 1c9cdc778592bb53866ec3b092c794f571f0b3c3

Before merge

None.

Findings

None.

Agent review details

How this fits together

The embedded runner reads admitted watch targets and session titles, renders bounded awareness text, and passes it through the existing runtime-context carrier into model requests.

flowchart LR
  A[Watch registry] --> C[Watch snapshot preparer]
  B[Session titles] --> C
  C --> D[Embedded prompt preparation]
  D --> E[Current turn runtime context]
  E --> F[Provider request]
  G[Retained conversation history] --> F
Loading

Technical review

Best possible solution:

Land the focused relocation through the existing watch preparer and runtime-context carrier.

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

Current-main source places mutable watched-session facts in the system prompt, and the PR records a negative control failing on that placement; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch uses the existing preparation, rendering, and turn-context owners, preserves separate SDK and compaction contracts, and explicitly supersedes removed watches with an empty snapshot.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 798570bc460f.

Provenance checked

  • Watched-session prompt placement changes intended behavior with a stated reason (895bf61: Tell the model which watched same-agent groups it can read, using bounded deterministic text without widening access.)
  • Asynchronous watch preparation keeps the original intent (ad3762e: Move watch and title reads off the Gateway thread while preserving disclosure checks and released synchronous SDK behavior.)
  • Accepted tool and permission refresh keeps the original intent (67433ff: Apply active permission changes through the existing run owner and accept prepared prompt state at the model boundary.)
  • Prompt-phase ownership keeps the original intent (f82895d: Keep prompt assembly, admission, dispatch, and recovery together in the extracted prompt lifecycle.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit 895bf61 adds src/agents/watched-sessions-prompt.ts:38 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 895bf61ea0d3; files: src/agents/watched-sessions-prompt.ts)
  • Peter Steinberger: Raw commit ad3762e adds src/agents/watched-sessions-prompt.ts:51 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ad3762ef8d2a; files: src/agents/watched-sessions-prompt.ts)

PR surface

Source +38, Tests +81, Docs +5. Total +124 across 5 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 50 12 +38
Tests 1 81 0 +81
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 136 12 +124

Review metrics

Metric Value Why it matters
Production versus test growth Production +50/−12; tests +81/−0 The production growth carries admitted and empty snapshots through existing owners; the regression covers membership, rename, removal, refresh, and excluded modes.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Repairs unnecessary prompt-prefix invalidation on compatible provider routes without an established outage or access-policy regression.
  • 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.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (5 earlier review cycles)
  • reviewed 2026-10-24T07:32:44.612Z sha 5e06d92c71d5d8b44a67de0af4ec471adae90d26 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-24T22:32:07.134Z sha 5e06d92c71d5d8b44a67de0af4ec471adae90d26 :: needs changes before merge. :: none
  • reviewed 2026-10-25T12:46:53.756Z sha 0cea440 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-26T03:16:32.044Z sha 8dbbbf7 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-26T06:37:07.351Z sha 1c9cdc7 :: needs maintainer review before merge. :: none

Reviewed October 26, 2026, 4:49 AM ET / 08:49 UTC (Revision 6).

@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 24, 2026
@ensignwesley
ensignwesley force-pushed the fix/watched-session-turn-context branch from 5e06d92 to 0cea440 Compare October 25, 2026 05:24
@ensignwesley

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 25, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@steipete
steipete merged commit bae5127 into openclaw:main Oct 26, 2026
154 of 157 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 27, 2026
…penclaw#182354)

Related: openclaw#114797

## What Problem This Solves

Adding, renaming, or removing watched groups changes the system-prompt suffix ahead of existing conversation history on compatible provider routes. That invalidates an otherwise reusable request prefix.

## User Impact

Watched-group awareness stays current without rewriting earlier model context. Existing same-agent, main-session, read-tool, sandbox, and full-prompt visibility checks remain in force. No configuration or migration is required.

## Why This Change Was Made

Carry the watch owner's admitted snapshot in the existing current-turn runtime context, including an explicit empty snapshot after the last readable watch disappears. Tool-context refresh accepts the refreshed snapshot without putting it back into the system prompt. The released synchronous SDK and separate compaction prompt keep their existing contracts.

The simplification pass retained one watch preparer and one existing runtime-context carrier. Production is +50/-12 (net +38), tests +81/-0, and documentation +5/-0. The remaining growth carries the snapshot and its empty state through those existing owners; no new cache, registry, or persistence owner is introduced.

Thanks @ensignwesley for the original repair and regression.

## Evidence

- Published head: `1c9cdc778592bb53866ec3b092c794f571f0b3c3`; contributor commits remain intact.
- Fresh negative control: the added regression fails against unchanged main production at `9c7a111ce1f035d688e0d3d24864c98d2ad18feb`, specifically because the watched title appears in the system prompt. The failing case took 7.692 s; the cold command took 318.79 s.
- Fresh candidate verification: the four exact changed TypeScript blobs from this head passed all 50 tests across prompt preparation, watched sessions, and `agent-tools.prefix-stability.test.ts` in the same tooling checkout. The regression took 5.193 s; total command wall time was 377.17 s, mostly compilation/runner startup. Targeted oxlint and oxfmt passed. These local checks used the tooling checkout's surrounding main code; exact-head CI supplies whole-revision proof.
- Exact-head CI run [40279901199](https://github.com/openclaw/openclaw/actions/runs/40279901199) passed, including `openclaw/ci-gate`; the published security/dependency gate also passed.
- Prior source-Gateway HTTP proof at `8dbbbf71e18e3dcc71bb6c9c1c45d2fd89788ec2` exercised empty → add → cold reopen/rename → removal across two isolated Gateway processes. System/tool bytes and previous message prefixes stayed identical, current watch facts reached each new turn, and removal supplied an empty snapshot. The three production owners are byte-identical to this head, verified again during this review.
- That prior integration also recorded a local Qwen2.5 7B/Ollama control, a full build, targeted types, and `pnpm prompt:snapshots:gen` with zero generated delta. These are retained prior-head results, not newly rerun claims.

- Fresh independent Codex review completed with a validated scoped-clean result at P0–P2; no actionable findings. Documentation formatting and a conflict-free merge-tree check against current main also passed.

No fresh live Gateway or external-provider run was performed in this pass: the recorded transport proof covers unchanged production bytes, and the fresh checks target the owning regression. No inbound `chat.send`, real channel round-trip, cache-hit-rate, or latency claim is made.

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. 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.

2 participants