Skip to content

Emit sessions.changed for in-chat command metadata - #88690

Closed
alexzhu0 wants to merge 6 commits into
openclaw:mainfrom
alexzhu0:fix/sessions-changed-in-chat-commands
Closed

alexzhu0 wants to merge 6 commits into
openclaw:mainfrom
alexzhu0:fix/sessions-changed-in-chat-commands

Conversation

@alexzhu0

@alexzhu0 alexzhu0 commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #88598

User-facing bug

Control UI clients subscribed to session updates could miss metadata changes made by in-chat commands. A command-only turn such as /goal complete, /goal pause, or /goal clear can update the session store without starting a model run, but the Gateway did not emit a sessions.changed event for that mutation. The visible session row could keep stale goal/status metadata until a manual reload or another unrelated session event.

Exact repro

Source-level reproduction:

  1. Connect a Control UI/WebChat client that subscribes to sessions.changed.
  2. Send an in-chat /goal command that mutates the persisted session goal, for example /goal complete shipped.
  3. The command handler writes the updated goal to the session store and returns command output.
  4. Before this patch, no command-metadata sessions.changed event was broadcast for the store write, so subscribed clients did not get a scoped refresh for that session.

Fix summary

  • Add a typed onSessionMetadataChanged reply option for command handlers.
  • Notify after successful command-session store writes through the shared persistSessionEntry helper.
  • Notify /goal start, pause, resume, complete, blocked, clear, and status paths when they actually change the persisted goal metadata.
  • Share the Gateway sessions.changed emitter between session RPC handlers and chat.send, so command-only chat turns can broadcast a scoped session row update.
  • Delay command-metadata broadcasts until after the current command turn leaves the active-run map, while still preserving hasActiveRun: true if another run for the same session is active.
  • Fall back to the shared session lifecycle event bus when command metadata changes happen outside chat.send, so raw channel dispatchers that use the same command-session store helper also refresh Gateway subscribers.
  • Preserve selected-agent global alias handling so canonical global updates still refresh a selected agent:<id>:global Control UI/WebChat session, and normalize command lifecycle metadata from agent:<id>:global back to sessionKey: "global" plus agentId.
  • Include live session setting metadata (thinkingLevels, thinkingOptions, thinkingDefault) on command-metadata sessions.changed events when a read-only catalog is available, avoid overwriting richer UI metadata when catalog discovery is unavailable or slow, and reuse the TUI-loaded model catalog when rebuilding embedded session defaults.
  • Document that command-only session metadata changes refresh subscribed clients.

Targeted tests

  • Added /goal command unit coverage for metadata-change notifications on mutating goal actions and no-op clear paths.
  • Added /goal command unit coverage for the shared lifecycle fallback when no direct Gateway subscriber callback is installed.
  • Added Gateway sessions coverage for command-metadata sessions.changed payloads, active-run exclusion, catalog-backed thinking metadata, slow catalog fallback, hidden internal runs, selected global runs, and default-agent scoped literal global active runs.
  • Added Gateway chat coverage proving command-only /goal turns broadcast scoped session updates and do not report their own command turn as active.
  • Added Gateway lifecycle coverage proving command metadata lifecycle events are broadcast to session subscribers.
  • Added command-store coverage proving scoped global metadata is canonicalized to sessionKey: "global" plus the parsed agent id.
  • Added UI controller coverage for canonical global deltas against selected agent-global aliases.
  • Added embedded TUI coverage proving history model catalogs are reused for session metadata/defaults and history still loads when catalog discovery fails.

Real behavior proof

Behavior addressed: In-chat command metadata writes now emit scoped sessions.changed events, so subscribed Control UI/WebChat clients can refresh visible session metadata after command-only turns.

Real environment tested: Local OpenClaw checkout on branch fix/sessions-changed-in-chat-commands, commit 677e3d3c01d3df9943da18e7b4509dc618797606, rebased onto current origin/main at 9cbf18293b. The Gateway proof exercises the sessions.changed command-metadata path used by subscribed Control UI/WebChat clients.

Exact steps or command run after this patch:

  • git diff --check origin/main...HEAD
  • ./node_modules/.bin/oxlint src/auto-reply/reply/commands-session-store.ts src/auto-reply/reply/commands-session-store.test.ts src/gateway/server-methods/session-change-events.ts src/gateway/server-methods/optional-model-catalog.ts src/gateway/session-utils.ts src/gateway/server-methods/sessions.ts src/gateway/server-methods/chat.ts src/gateway/server.sessions.list-changed.test.ts src/tui/embedded-backend.ts src/tui/embedded-backend.test.ts
  • OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree CI=1 NODE_OPTIONS=--max-old-space-size=4096 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=120000 OPENCLAW_VITEST_NO_OUTPUT_HEARTBEAT_MS=10000 node scripts/run-vitest.mjs --run --maxWorkers 1 src/auto-reply/reply/commands-session-store.test.ts
  • OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree CI=1 NODE_OPTIONS=--max-old-space-size=4096 OPENCLAW_VITEST_NO_OUTPUT_TIMEOUT_MS=120000 OPENCLAW_VITEST_NO_OUTPUT_HEARTBEAT_MS=10000 node scripts/run-vitest.mjs --run --maxWorkers 1 src/auto-reply/reply/commands-goal.test.ts src/auto-reply/reply/commands-session-store.test.ts src/auto-reply/reply/directive-handling.mixed-inline.test.ts src/gateway/server.sessions.list-changed.test.ts ui/src/ui/controllers/chat.test.ts src/tui/embedded-backend.test.ts
  • CI=1 NODE_OPTIONS=--max-old-space-size=4096 node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test-88690-rebase.tsbuildinfo
  • node --import tsx src/entry.ts --version
  • node --import tsx .artifacts/pr-88690-fn-proof.mjs (function-level real-behavior proof on the current head; see below)
  • node --import tsx .artifacts/pr-88690-sessions-changed-proof.mjs (full live-gateway subscriber proof; captured on a prior head — see the note below on why it cannot re-run in this no-build checkout)
  • codex review --base origin/main

Evidence after fix:

  • git diff --check origin/main...HEAD passed.
  • Direct oxlint on the touched command/gateway/TUI files passed.
  • Focused command-store regression passed: Test Files 1 passed (1), Tests 4 passed (4). This includes the scoped-global proof that agent:target:global metadata notifications become sessionKey: "global" with agentId: "target".
  • Expanded command/gateway/UI/TUI regression run passed after rebasing onto current origin/main: 10 focused test files, 431 tests passed (auto-reply command + directive-handling suites, src/gateway/server.chat.gateway-server-chat.test.ts, src/gateway/server.sessions.list-changed.test.ts, src/gateway/session-message-events.test.ts, src/tui/embedded-backend.test.ts, ui/src/ui/controllers/chat.test.ts). Core + UI tsgo typecheck both passed with exit 0; oxlint passed on all changed src/ and ui/ files.
  • run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json exited successfully.
  • Source CLI entry check passed: OpenClaw 2026.6.2 (677e3d3).
  • Standalone WebSocket subscriber proof passed against a local Gateway launched from the source CLI entry. The proof created an isolated temporary OPENCLAW_HOME, OPENCLAW_STATE_DIR, and OPENCLAW_CONFIG_PATH, preloaded one session with an active goal, connected one operator client that only subscribed to sessions.changed, connected a second operator client that sent /goal complete redacted websocket proof through chat.send, and did not call chat.history.
  • codex review --base origin/main found no discrete, actionable correctness issue after the scoped-global fix. Its sandboxed gateway socket shard was blocked by listen EPERM on 127.0.0.1, while the expanded Gateway-containing regression above passed outside that sandbox restriction.
  • Copied terminal output from the expanded local regression after the rebase:
RUN  v4.1.7 /Users/alex/PR/projects/openclaw__openclaw/repo

Test Files  8 passed (8)
Tests  172 passed (172)
Test Files  1 passed (1)
Tests  40 passed (40)
Test Files  5 passed (5)
Tests  100 passed (100)
Test Files  1 passed (1)
Tests  119 passed (119)

Copied redacted standalone subscriber proof:

{
  "ok": true,
  "pr": 88690,
  "proof": "standalone websocket subscriber",
  "command": "/goal complete redacted websocket proof",
  "token": "<redacted-gateway-token>",
  "sessionKeySent": "main",
  "event": "sessions.changed",
  "reason": "command-metadata",
  "eventSessionKey": "agent:main:main",
  "sessionId": "sess-pr-88690-proof",
  "label": "PR 88690 sessions.changed proof",
  "goalStatus": "complete",
  "goalObjective": "redacted PR 88690 websocket subscriber proof objective",
  "hasActiveRun": false,
  "chatSendStatus": "started",
  "chatSendRunId": "<redacted-run-id>",
  "subscriberSawEventBeforeHistoryReload": true,
  "chatHistoryCallsSent": 0,
  "isolatedState": {
    "configPath": "<redacted-temp-openclaw.json>",
    "stateDir": "<redacted-temp-state-dir>",
    "storePath": "<redacted-temp-sessions-json>"
  },
  "localStorePathExisted": true
}

Observed result after fix: Command-only /goal metadata mutations produce scoped sessions.changed broadcasts with fresh session row metadata. A standalone WebSocket subscriber receives the command-metadata event before any history reload, and the payload excludes the transient command-only chat.send active run (hasActiveRun: false). chat.send keeps selected agent-global aliases receiving canonical global deltas, slow or failed model catalog discovery does not block the broadcast or TUI history, and non-chat.send command paths get the shared lifecycle fallback instead of leaving subscribers stale.

Note on the standalone subscriber proof above: that JSON was captured on a prior head. This refresh is a rebase onto current origin/main (9cbf18293b). The only conflict on the sessions.changed path was a one-line import union in chat.ts (kept main's new updateSessionStoreEntry alongside this PR's SessionMetadataChangedEvent type import); the patched event-emitting function dispatchSessionMetadataChanged (src/auto-reply/reply/commands-session-store.ts) is byte-for-byte identical to the prior head, and the 431-test focused suite (including the scoped-global regression and ui/src/ui/controllers/chat.test.ts) passes on this head. The full live-gateway subscriber script could not be re-run in this checkout because the gateway's provider-auth worker thread fails to resolve src/agents/auth-profiles.js (a tsx-worker/no-build limitation of running from source, unrelated to this PR). To prove the patched path on this exact head without that environment dependency, I ran the patched exported function directly:

$ node --import tsx .artifacts/pr-88690-fn-proof.mjs

The script imports the real dispatchSessionMetadataChanged (src/auto-reply/reply/commands-session-store.ts), passes a real subscriber callback, and prints the events the patched code actually emits on commit 677e3d3c01:

{
  "ok": true,
  "pr": 88690,
  "proof": "function-level dispatchSessionMetadataChanged",
  "results": [
    {
      "case": "agent-scoped key derives agentId from the key (not the caller agentId)",
      "input": { "sessionKey": "agent:target:telegram:direct:123", "agentId": "main", "reason": "command-metadata" },
      "emittedToSubscriber": { "sessionKey": "agent:target:telegram:direct:123", "agentId": "target", "reason": "command-metadata" }
    },
    {
      "case": "scoped-global key canonicalizes to global row + parsed agent",
      "input": { "sessionKey": "agent:target:global", "agentId": "main", "reason": "command-metadata" },
      "emittedToSubscriber": { "sessionKey": "global", "agentId": "target", "reason": "command-metadata" }
    },
    {
      "case": "plain global keeps fallback agentId",
      "input": { "sessionKey": "global", "agentId": "target", "reason": "command-metadata" },
      "emittedToSubscriber": { "sessionKey": "global", "agentId": "target", "reason": "command-metadata" }
    }
  ]
}

This proves the patched dispatch on the current head: an agent-scoped session key derives its agentId from the key (target, not the caller's main), a scoped agent:target:global key canonicalizes to the global row with the parsed agent, and a plain global key keeps its fallback agent — each delivered to a live subscriber callback as a command-metadata event.

What was not tested: Full gateway/core suites and full pnpm check were not run. I did not run a browser-rendered Control UI session; the added proof uses the same Gateway WebSocket subscription contract that Control UI/WebChat clients consume. The Gateway tests and standalone proof require local 127.0.0.1 listening; default sandboxed review attempts returned listen EPERM, so I reran the expanded Gateway-containing regression and standalone subscriber proof with elevated local-network permission. I did not implement or test /name because this checkout does not contain a /name handler.

Not tested / known gaps

  • This patch focuses on command metadata changes that happen through chat.send reply options and the shared command-session store helper.
  • Channel command flows that bypass the shared command-session store helper are unchanged.
  • Full gateway/core suites and full pnpm check were not run in this remediation pass.

AI-assisted disclosure

This patch was prepared with AI assistance. I used source-level reproduction, targeted regression tests, and codex review --base origin/main to validate the behavior above.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: L proof: supplied External PR includes structured after-fix real behavior proof. labels May 31, 2026
@clawsweeper

clawsweeper Bot commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 5, 2026, 11:44 PM ET / 03:44 UTC.

Summary
The PR threads command-driven session metadata changes from auto-reply handlers into Gateway sessions.changed broadcasts, updates /goal, directive, abort, selected-global, UI/TUI metadata paths, docs, and focused tests.

PR surface: Source +386, Tests +891, Docs +2. Total +1279 across 31 files.

Reproducibility: yes. source-level. Current main persists /goal and command session-store metadata without a sessions.changed callback, while sessions.patch already has the subscriber refresh path; I did not run a live repro in this read-only review.

Review metrics: 1 noteworthy metric.

  • Event contract additions: 2 added. The PR adds a typed command metadata callback and optional lifecycle-event agentId, so maintainers should review the session-state subscriber contract before merge.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Maintainer review should focus on selected-global scoping, active-run exclusion, and whether browser-row proof is required before merge.

Mantis proof suggestion
A visible Control UI/WebChat proof would materially reduce the remaining confidence gap around row refresh behavior, although the current live-output proof is sufficient for the event contract. A maintainer can ask Mantis to capture proof by posting a new PR comment that starts with the OpenClaw Mantis account mention, followed by:

visual task: verify that a command-only /goal complete refreshes the subscribed Control UI/WebChat session row without manual reload.

Risk before merge

  • [P1] This is a session-state fanout change: a selected-global, payload-shape, or active-run projection mistake could leave Control UI/WebChat/TUI rows stale or associated with the wrong agent even with focused tests passing.
  • [P1] The related /name work at feat(commands): add /name to rename the current session from chat #88581 will need to rebase onto this shared notification path or preserve equivalent live session metadata refresh behavior.

Maintainer options:

  1. Land after session-event owner review (recommended)
    Have a maintainer confirm the command-metadata payload, selected-global scoping, and active-run semantics, then merge with the supplied focused tests and proof if checks remain acceptable.
  2. Request browser-row proof first
    Ask for a Control UI/WebChat recording or diagnostic output showing command-only /goal metadata refreshing a visible row without reload if UI-level confidence is required.
  3. Split if the contract feels too broad
    If the shared emitter, catalog metadata, and global-alias handling are too much for one merge, pause this PR and split the event-contract extraction from command callback wiring.

Next step before merge

  • No automated repair is queued; the remaining action is maintainer review of the session-state event contract and merge readiness.

Security
Cleared: The diff does not change dependencies, workflows, package scripts, credentials, permissions, or other concrete security or supply-chain surfaces.

Review details

Best possible solution:

Land the shared command-metadata sessions.changed path after maintainer review confirms the session-event contract, then have related command work reuse the same seam.

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

Yes, source-level. Current main persists /goal and command session-store metadata without a sessions.changed callback, while sessions.patch already has the subscriber refresh path; I did not run a live repro in this read-only review.

Is this the best way to solve the issue?

Yes, this appears to be the best fix shape. It threads a narrow typed metadata signal to the Gateway context that can broadcast, reuses a shared sessions.changed emitter, and covers sibling command, lifecycle, UI, and TUI paths instead of adding a one-off command refresh.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 092075534e54.

Label changes

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes redacted live Gateway WebSocket subscriber output for the command-metadata event path plus exact-head function-level output and focused regression output.

Label justifications:

  • P2: This fixes a normal-priority stale session metadata refresh bug with limited blast radius in command-driven session updates.
  • merge-risk: 🚨 session-state: The diff changes sessions.changed payload construction, selected-global scoping, and active-run projection for session subscribers.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes redacted live Gateway WebSocket subscriber output for the command-metadata event path plus exact-head function-level output and focused regression output.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes redacted live Gateway WebSocket subscriber output for the command-metadata event path plus exact-head function-level output and focused regression output.
Evidence reviewed

PR surface:

Source +386, Tests +891, Docs +2. Total +1279 across 31 files.

View PR surface stats
Area Files Added Removed Net
Source 20 521 135 +386
Tests 10 904 13 +891
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 31 1427 148 +1279

What I checked:

  • Repository policy applied: Root and scoped Gateway, server-methods, UI, docs, and TUI AGENTS.md files were read; the session-state compatibility and whole-path review guidance affected this verdict. (AGENTS.md:23, 092075534e54)
  • Current main lacks command metadata fanout: Current main's shared command session-store helper persists entries and abort metadata but returns without a metadata callback or lifecycle event. (src/auto-reply/reply/commands-session-store.ts:9, 092075534e54)
  • Current main emitter is RPC-local: Current main has a module-local emitSessionsChanged inside session RPC handling, so the auto-reply command pipeline cannot reuse it directly. (src/gateway/server-methods/sessions.ts:288, 092075534e54)
  • PR adds typed command metadata dispatch: The PR head adds dispatchSessionMetadataChanged and calls notification after successful command session-store persistence, including scoped global canonicalization. (src/auto-reply/reply/commands-session-store.ts:43, 677e3d3c01d3)
  • PR shares Gateway sessions.changed emission: The PR head extracts emitSessionsChanged, loads optional read-only model catalog metadata, preserves active-run calculation, and supports excluding the command-only run id. (src/gateway/server-methods/session-change-events.ts:102, 677e3d3c01d3)
  • PR wires chat.send to command metadata events: chat.send queues onSessionMetadataChanged events from the reply pipeline and flushes them through the shared emitter after command-only dispatch, excluding the transient command run when no model run starts. (src/gateway/server-methods/chat.ts:3362, 677e3d3c01d3)

Likely related people:

  • steipete: Public commit history shows recent work on Gateway session methods, hidden-run visibility, chat-history session metadata, and the core session goals feature that this command-metadata path extends. (role: recent area contributor; confidence: medium; commits: a509c48f0ea2, 6ad73e173b1a, 2682c027746b; files: src/gateway/server-methods/sessions.ts, src/auto-reply/reply/commands-goal.ts, src/gateway/server-methods/chat.ts)
  • vincentkoc: Public history ties this contributor to recent /goal command behavior, optional model catalog loading, and Control UI chat startup metadata surfaces that this PR reuses. (role: adjacent owner; confidence: medium; commits: dd8d52c7d9c6, dc5b3ecc4c52, 56995069f132; files: src/gateway/server-methods/optional-model-catalog.ts, src/auto-reply/reply/commands-goal.ts, ui/src/ui/controllers/chat.ts)
  • zhangguiping-xydt: Public history shows recent fixes to Control UI chat stream and session reconciliation behavior, which is the subscriber side of this PR's sessions.changed change. (role: recent UI lifecycle contributor; confidence: medium; commits: c2d7b4a486b1, 0b98aea71a52; files: ui/src/ui/controllers/chat.ts, ui/src/ui/controllers/sessions.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. labels May 31, 2026
@alexzhu0
alexzhu0 force-pushed the fix/sessions-changed-in-chat-commands branch from 3623771 to d1c02d6 Compare May 31, 2026 17:42
@openclaw-barnacle openclaw-barnacle Bot added triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. and removed proof: supplied External PR includes structured after-fix real behavior proof. labels May 31, 2026
@alexzhu0
alexzhu0 force-pushed the fix/sessions-changed-in-chat-commands branch from d1c02d6 to fff0305 Compare May 31, 2026 17:56
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels May 31, 2026
@alexzhu0
alexzhu0 force-pushed the fix/sessions-changed-in-chat-commands branch from fff0305 to a249595 Compare May 31, 2026 18:09
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels May 31, 2026
@alexzhu0
alexzhu0 force-pushed the fix/sessions-changed-in-chat-commands branch from a249595 to be2b9c2 Compare May 31, 2026 21:23
@alexzhu0
alexzhu0 force-pushed the fix/sessions-changed-in-chat-commands branch from be2b9c2 to 4b2c2f3 Compare May 31, 2026 22:00
@alexzhu0
alexzhu0 marked this pull request as ready for review June 1, 2026 02:05
@alexzhu0
alexzhu0 force-pushed the fix/sessions-changed-in-chat-commands branch from 4b2c2f3 to 395128d Compare June 1, 2026 02:24
@BSG2000

BSG2000 commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Cross-linking from #88581 / #88598: this shared command-metadata sessions.changed seam is directly relevant to the /name command PR.

If this lands, #88581 should rebase onto it and use the same notification path for successful /name session-label writes instead of keeping the documented reload-only behavior. #88479 is only indirectly related because it goes through sessions.patch, which already has a refresh path.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: mock-only-proof Candidate: PR proof only shows tests, mocks, snapshots, lint, typecheck, or CI. labels Jun 1, 2026
@clawsweeper clawsweeper Bot removed the rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. label Jun 1, 2026
@alexzhu0

alexzhu0 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 2, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. 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 Jun 2, 2026
@alexzhu0
alexzhu0 force-pushed the fix/sessions-changed-in-chat-commands branch from b97bcf5 to 1205389 Compare June 3, 2026 14:11
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 3, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 3, 2026
@alexzhu0
alexzhu0 force-pushed the fix/sessions-changed-in-chat-commands branch from 1205389 to 7145447 Compare June 4, 2026 13:03
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 4, 2026
alexzhu0 added 6 commits June 6, 2026 11:20
Constraint: Gateway subscribers depend on sessions.changed to refresh visible session rows after command-only metadata writes.

Rejected: Reply-payload-only refresh | command-only turns can mutate store without a model reply, directive-only turns persist outside command handlers, mixed inline directive fast-lane writes happen before the persistence pass, and stop/abort writes target session metadata directly.

Confidence: high

Scope-risk: moderate

Directive: Keep command metadata notifications tied to successful store writes or verified persisted goal/directive/abort changes, derive event agent scope from the changed session key, and never let command-only turns project themselves as the only active run.

Tested: node scripts/docs-list.js; git diff --check origin/main; OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/auto-reply/reply/commands-goal.test.ts src/auto-reply/reply/directive-handling.model.test.ts src/auto-reply/reply/directive-handling.mixed-inline.test.ts src/auto-reply/reply/commands-stop-target.test.ts src/auto-reply/reply/commands-session-store.test.ts -t "metadata|mixed inline directives|directive-only handling mutates|fast-lane metadata|directive persistence mutates|passes session metadata|goal|command session metadata"; OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/gateway/session-message-events.test.ts src/gateway/server.sessions.list-changed.test.ts src/gateway/server.chat.gateway-server-chat.test.ts -t "broadcasts command metadata lifecycle changes|chat.send broadcasts sessions.changed when in-chat command metadata changes|sessions.changed command metadata excludes only the command run from active state"

Not-tested: Full core typecheck due existing ui/src/ui/views/workboard-3d-game.ts missing three type resolution and implicit any errors; live browser Control UI with a real long-running /goal turn.
Constraint: chat.send active runs for selected global agents are tracked as agent:<id>:global.\nRejected: Passing caller-supplied hasActiveRun everywhere | duplicates session activity logic across command paths.\nConfidence: high\nScope-risk: narrow\nDirective: Keep sessions.changed active-state resolution centralized in emitSessionsChanged.\nTested: OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/gateway/server.sessions.list-changed.test.ts -t selected-global/command-metadata focus.\nNot-tested: Manual browser Control UI websocket session switching.
Constraint: openclaw#88598 requires in-chat command metadata to reach WebChat, Control UI, and embedded TUI consumers without waiting for a later list refresh.

Rejected: relying on periodic sessions.list refresh | it leaves live chat and embedded history consumers with stale selected-session metadata.

Confidence: high

Scope-risk: narrow

Directive: Keep session-row lifecycle events and chat event session-key aliasing aligned when adding new agent-scoped global aliases.

Tested: OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs ui/src/ui/controllers/chat.test.ts src/tui/embedded-backend.test.ts src/gateway/server.sessions.list-changed.test.ts -t 'canonical global|history model catalog|live session setting metadata' (gateway shard rerun with local listen permission); OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/auto-reply/reply/commands-goal.test.ts src/auto-reply/reply/directive-handling.model.test.ts src/auto-reply/reply/directive-handling.mixed-inline.test.ts src/auto-reply/reply/commands-stop-target.test.ts src/auto-reply/reply/commands-session-store.test.ts -t 'metadata|mixed inline directives|directive-only handling mutates|fast-lane metadata|global-session|directive persistence mutates|passes session metadata|goal|command session metadata'; OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/gateway/session-message-events.test.ts src/gateway/server.sessions.list-changed.test.ts src/gateway/server.chat.gateway-server-chat.test.ts -t 'broadcasts command metadata lifecycle changes|chat.send broadcasts sessions.changed when in-chat command metadata changes|sessions.changed command metadata excludes only the command run from active state|sessions.changed command metadata marks selected global runs active|sessions.changed mutation events include live session setting metadata'; git diff --check origin/main

Not-tested: full pnpm test suite and browser screenshot flow.
Constraint: upstream main removed the old session-model-catalog helper during rebase.
Rejected: recreate session-model-catalog.js | duplicating the upstream optional-model-catalog helper would widen this PR.
Confidence: high
Scope-risk: narrow
Directive: Keep future session metadata event changes aligned with the shared server-method catalog loader.
Tested: env OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs ui/src/ui/controllers/chat.test.ts src/tui/embedded-backend.test.ts -t "canonical global|history model catalog"; env OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/auto-reply/reply/commands-goal.test.ts src/auto-reply/reply/directive-handling.model.test.ts src/auto-reply/reply/directive-handling.mixed-inline.test.ts src/auto-reply/reply/commands-stop-target.test.ts src/auto-reply/reply/commands-session-store.test.ts -t "metadata|mixed inline directives|directive-only handling mutates|fast-lane metadata|global-session|directive persistence mutates|passes session metadata|goal|command session metadata"; env OPENCLAW_HEAVY_CHECK_LOCK_SCOPE=worktree OPENCLAW_VITEST_MAX_WORKERS=1 node scripts/run-vitest.mjs src/gateway/session-message-events.test.ts src/gateway/server.sessions.list-changed.test.ts src/gateway/server.chat.gateway-server-chat.test.ts -t "broadcasts command metadata lifecycle changes|chat.send broadcasts sessions.changed when in-chat command metadata changes|sessions.changed command metadata excludes only the command run from active state|sessions.changed command metadata marks selected global runs active|sessions.changed mutation events include live session setting metadata"
Not-tested: full pnpm test suite
Constraint: Keep openclaw#88690 focused on Control UI/WebChat session update metadata and accepted review feedback.
Rejected: Broadcasting command metadata for hidden/internal runs | it reintroduces stale Control UI running indicators.
Confidence: high
Scope-risk: moderate
Directive: Treat literal global metadata as default-agent scoped unless the event carries an explicit agent id.
Tested: git diff --check origin/main...HEAD; focused gateway sessions.changed command metadata Vitest; codex review --base origin/main.
Not-tested: Broader auto-reply rerun stalled under the local no-output guard; full gateway suite not run.
Constraint: openclaw#88690 CI rejected an unsafe catch callback and a TUI mock spread with non-tuple args.
Rejected: broad refactor of chat command refresh plumbing | existing branch already has behavior tests and only CI hygiene failed.
Confidence: high
Scope-risk: narrow
Directive: Keep future CI-only followups restricted to failing lint/type surfaces unless behavior evidence changes.
Tested: git diff --check origin/main...HEAD; ./node_modules/.bin/oxlint src/gateway/server-methods/chat.ts src/tui/embedded-backend.test.ts; CI=1 NODE_OPTIONS=--max-old-space-size=4096 node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.core.test.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/core-test.tsbuildinfo; node scripts/run-vitest.mjs src/tui/embedded-backend.test.ts src/gateway/server.sessions.list-changed.test.ts src/gateway/server.chat.gateway-server-chat.test.ts; codex review --base origin/main.
Not-tested: node scripts/run-oxlint-shards.mjs --threads=8 because this local checkout lacks the tsgolint executable required by the shard wrapper.
@alexzhu0
alexzhu0 force-pushed the fix/sessions-changed-in-chat-commands branch from 7145447 to 677e3d3 Compare June 6, 2026 03:37
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 6, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 6, 2026
@alexzhu0

alexzhu0 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor Author

Closing this — superseded by c682919808 ("fix(gateway): notify session changes from goal commands"), which landed on main and resolved #88598 (now closed as completed).

That change already covers the core of this PR: a shared command-metadata seam (markCommandSessionMetadataChanged / takeCommandSessionMetadataChanges), the scoped-global canonicalization (global + agentId derivation, omitUnscopedGlobalGoal), and the /goal notification paths emitting sessions.changed via emitSessionsChanged. No reason to keep a parallel implementation of the same seam.

For anyone following the cross-link from #88581 / #88598 (cc @BSG2000): the canonical seam to build on is now command-session-metadata.ts + session-change-event.ts on main, not this PR.

Thanks @vincentkoc — closing in favor of the merged version.

@alexzhu0 alexzhu0 closed this Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

Emit sessions.changed for store-mutating in-chat commands (/name, /goal)

2 participants