Skip to content

fix(gateway): fire session:patch hooks for model changes - #82257

Merged
giodl73-repo merged 2 commits into
openclaw:mainfrom
giodl73-repo:fix-session-patch-model-hooks-62751
May 16, 2026
Merged

giodl73-repo merged 2 commits into
openclaw:mainfrom
giodl73-repo:fix-session-patch-model-hooks-62751

Conversation

@giodl73-repo

@giodl73-repo giodl73-repo commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • route successful /model directive-only updates through the existing session:patch hook event
  • fire the same hook when inline model directives and session_status({ model }) persist a changed model override
  • keep sessions.patch on the same shared hook dispatch helper and add focused regressions for /model and session_status

Fixes #62751.

Tests

  • CI=1 node scripts/run-vitest.mjs src/gateway/server.sessions.permissions-hooks.test.ts src/gateway/sessions-patch.test.ts src/auto-reply/reply/directive-handling.model.test.ts src/agents/openclaw-tools.session-status.test.ts
  • pnpm exec oxfmt --check --threads=1 src/gateway/server-methods/sessions.ts src/gateway/sessions-patch.ts src/gateway/session-patch-hooks.ts src/auto-reply/reply/directive-handling.impl.ts src/auto-reply/reply/directive-handling.persist.ts src/agents/tools/session-status-tool.ts src/gateway/server.sessions.permissions-hooks.test.ts src/gateway/sessions-patch.test.ts src/auto-reply/reply/directive-handling.model.test.ts src/agents/openclaw-tools.session-status.test.ts
  • pnpm check:changed

Real behavior proof

Behavior or issue addressed: session:patch hook events did not fire when a session model changed through /model or the session_status tool.

Real environment tested: local OpenClaw checkout on Ubuntu 24.04 under WSL, with the real hook registry and session persistence code paths exercised by the focused Vitest shards.

Exact steps or command run after this patch: CI=1 node scripts/run-vitest.mjs src/gateway/server.sessions.permissions-hooks.test.ts src/gateway/sessions-patch.test.ts src/auto-reply/reply/directive-handling.model.test.ts src/agents/openclaw-tools.session-status.test.ts.

Evidence after fix: before/after proof bundle published via Crabbox artifacts:

session-patch-model-hooks-before-after-proof.png

Observed result after fix: origin/main plus only the new regression specs fails because no hook event is observed; this PR branch passes the same focused shard and observes session:patch events with patch.model and the updated session entry.

What was not tested: live Discord/Telegram gateway delivery with a deployed workspace hook; this PR validates the source-level hook dispatch path used by those surfaces.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels May 15, 2026
@clawsweeper

clawsweeper Bot commented May 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
The PR extracts shared session:patch hook dispatch and calls it after successful model override persistence from /model, inline directives, and session_status(model=...), with focused regression tests.

Reproducibility: yes. at source level: register a session:patch hook, change the model via /model or session_status(model=...), and current main persists the model without a hook dispatch. The provided artifact also shows the new regression specs failing on origin/main and passing on the PR branch.

Real behavior proof
Needs real behavior proof before merge: The PR body and linked artifacts show focused Vitest before/after proof, but an external PR still needs redacted terminal/live output, logs, or a recording showing an enabled workspace hook receiving session:patch after /model or session_status; after updating the PR body, re-review should run automatically or a maintainer can comment @clawsweeper re-review. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, ask a maintainer to comment @clawsweeper re-review.

Next step before merge
Human handling is needed because the protected-label PR appears code-correct but still needs maintainer review and contributor-provided real behavior proof.

Security
Cleared: The diff adds internal hook dispatch calls and tests only; it does not change dependencies, workflows, secret handling, permissions, package resolution, or other supply-chain surfaces.

Review details

Best possible solution:

Land this PR or an equivalent helper after maintainer review and real behavior proof, preserving existing sessions.patch semantics while making successful model persistence emit the documented hook event.

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

Yes, at source level: register a session:patch hook, change the model via /model or session_status(model=...), and current main persists the model without a hook dispatch. The provided artifact also shows the new regression specs failing on origin/main and passing on the PR branch.

Is this the best way to solve the issue?

Yes, the code approach is the narrow maintainable fix: centralize the existing sessions.patch hook construction and call it only after successful model persistence in the missing paths. The blocker is proof and protected-label handling, not an observed code-shape defect.

What I checked:

Likely related people:

  • graciegould: PR history for the merged session patch hook work shows commits adding typed non-blocking session:patch dispatch, hook coverage, docs, and payload isolation. (role: introduced hook behavior; confidence: high; commits: 1b5380c173e0, 82f5c300bb76, 3c3b2774d31f; files: src/gateway/server-methods/sessions.ts, src/hooks/internal-hooks.ts, docs/automation/hooks.md)
  • obviyus: Authored the final merged payload-isolation commit for the session patch hook PR and has recent gateway session-path history. (role: follow-up hook contributor; confidence: medium; commits: 12ec0cd82201, 2d3f3de23549; files: src/gateway/server-methods/sessions.ts, src/hooks/internal-hooks.ts)
  • steipete: Recent history includes session-scoped model switch and session_status active-model changes, and local blame for current model persistence paths points to a broad recent touch by Peter Steinberger. (role: recent model and session-status area contributor; confidence: medium; commits: 546f81de0474, 3adce8fac12e, 628c753f3bff; files: src/auto-reply/reply/directive-handling.impl.ts, src/auto-reply/reply/directive-handling.persist.ts, src/agents/tools/session-status-tool.ts)

Remaining risk / open question:

  • The remaining proof gap is real runtime behavior: the posted artifacts are focused Vitest before/after logs, not output from an enabled workspace hook receiving session:patch after /model or session_status.
  • No local tests were run because this was a read-only review; validation evidence is source inspection plus the contributor's Crabbox artifact logs.

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

@giodl73-repo

Copy link
Copy Markdown
Contributor Author

OpenClaw QA Artifacts

Summary

Session model hook proof for PR #82257.

  • Before: origin/main 7715b29 with only the new regression specs fails because /model and session_status model changes persist without dispatching session:patch.
  • After: PR branch ebe9943 passes the same focused shard and observes session:patch events with patch.model and the updated session entry.
  • Artifact image: session-patch-model-hooks-before-after-proof.png
  • Logs: before-origin-main-with-regression-tests.log, after-pr-82257.log

Evidence

@giodl73-repo giodl73-repo changed the title Fire session:patch hooks for model changes fix(gateway): fire session:patch hooks for model changes May 15, 2026
@giodl73-repo
giodl73-repo merged commit dccf5f6 into openclaw:main May 16, 2026
113 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
)

* Fire session patch hooks for model changes

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

* chore: refresh CI after main repairs

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

---------

Co-authored-by: Copilot <[email protected]>
galiniliev pushed a commit to galiniliev/openclaw that referenced this pull request May 25, 2026
)

* Fire session patch hooks for model changes

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

* chore: refresh CI after main repairs

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

---------

Co-authored-by: Copilot <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
)

* Fire session patch hooks for model changes

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

* chore: refresh CI after main repairs

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

---------

Co-authored-by: Copilot <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
)

* Fire session patch hooks for model changes

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

* chore: refresh CI after main repairs

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

---------

Co-authored-by: Copilot <[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 gateway Gateway runtime maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

session:patch hook event not fired on model changes via /model or agent tool

1 participant