Skip to content

fix(hooks): reject malformed session keys and honor immediate wake overrides - #166406

Merged
steipete merged 2 commits into
mainfrom
fix/w10-l8
Oct 7, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/w10-l8

Conversation

@steipete

@steipete steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Two /hooks endpoint behaviors did something other than what the request asked for, without an error:

  1. Malformed session keys were silently ignored. An authenticated /hooks/agent request with a malformed sessionKey (null, a number, boolean, object, array, empty, or whitespace) returned 200 and dispatched to the fallback session, so the caller's routing intent was dropped without telling them.
  2. Transforms could not make a wake immediate. When a mapping was configured for next-heartbeat, a transform returning mode: "now" or wakeMode: "now" was ignored. Both the wake HTTP response and the agent job stayed deferred.

Why This Change Was Made

  1. normalizeAgentPayload in src/gateway/hooks.ts discarded supplied but invalid keys instead of rejecting them (behavior since 1ed5ca3fdeb). A supplied key must now be a valid session key, or the request gets 400 with nothing dispatched. An omitted key still uses the documented default.
  2. mergeAction in src/gateway/hooks-mapping.ts only recognized overrides toward the deferred mode (since aeb54555558). It now honors a transform's immediate override as well. Invalid transform values keep the existing fallback and validation.

User Impact

Hook callers get a clear 400 for bad session keys instead of a silent reroute, and transforms can make a wake immediate.

Evidence

  • Regressions: malformed keys returned 200 before the fix and return 400 with no dispatch after. A now override stayed next-heartbeat before and is honored after, in both the HTTP response and the job.
  • 12 related suites (205 tests) and the full check-changed gate passed remotely, and server.hooks.test.ts passed 19/19 on Linux.
  • An isolated CLI and Gateway on a remote box exercised missing or bad auth, 429 throttling and reset, malformed JSON, oversized bodies, invalid routing, queue-full 503, wake coalescing, restart, external-content wrapping with stub inference, mock-channel delivery, and eight concurrent replays with exactly one delivery.
  • Production +10/-2; tests +44; docs +4.

Found but not changed here: after a restart, an immediate wake followed quickly by an agent request using waitForCompletion can get a recorded 502 (AgentDatabaseRegistryChangedError) from the registry-ownership guard. This is being investigated separately; the guard is correct and stays.

@clawsweeper

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

@steipete
steipete marked this pull request as ready for review October 7, 2026 02:51
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 7, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 7, 2026
@clawsweeper

clawsweeper Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed October 6, 2026, 10:56 PM ET / October 7, 2026, 02:56 UTC.

ClawSweeper review

What this changes

The PR rejects malformed agent-hook session keys, honors immediate timing overrides from webhook transforms, and adds HTTP regressions and documentation.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: both fixes remain necessary on the pinned main branch, and no introduced correctness defect was found. The required test-cost evidence remains incomplete.

Priority: P2
Reviewed head: 38e824f7e2f7b69a7753dd2fc227a377809850ea

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with meaningful HTTP regressions and no blocking code findings; required test-cost reporting remains incomplete.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied Repository State identifies a MEMBER author, so the external-contributor proof gate does not apply. The body reports isolated Gateway after-fix checks matching both changed owners; no authority-bearing or stored-data contract changes require additional proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied Repository State identifies a MEMBER author, so the external-contributor proof gate does not apply. The body reports isolated Gateway after-fix checks matching both changed owners; no authority-bearing or stored-data contract changes require additional proof.
Evidence reviewed 10 items Introduced patch: The pinned introduction delta contains only the two validation/timing repairs, their HTTP regressions, and explanatory documentation.
Still necessary on main: The original main blob normalizes malformed session keys to undefined without rejecting them. Its transform merger recognizes only next-heartbeat overrides, so now cannot replace a deferred base action.
Timing repair preserves validation: Both timing fields now accept either documented enum value; invalid values retain the base/default fallback and the merged action still passes through validateAction.
Findings None None.
Security None None.

How this fits together

Gateway webhooks turn authenticated HTTP requests into wake events or agent runs. Payload validation and configured transforms determine routing and timing before dispatch.

flowchart TD
  A[HTTP hook request] --> B[Authentication]
  B --> C[Payload validation]
  B --> D[Configured mapping and transform]
  C --> E[Routing and session policy]
  D --> E
  E --> F[Wake event]
  E --> G[Agent run]
Loading

Before merge

  • Complete next step (P2) - Add the required before/after Gateway test benchmark, pnpm test src/gateway/server.hooks.test.ts --maxWorkers=1 wall time, and CI seconds to the PR evidence.
Agent review details

Security

None.

PR surface

Source +8, Tests +44, Docs +4. Total +56 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 10 2 +8
Tests 1 44 0 +44
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 58 2 +56

Review metrics

None.

Technical review

Best possible solution:

Keep routing validation at hook ingress and apply both supported timing overrides through the existing mapping owner.

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

Yes, from source: an authenticated agent request with a blank or non-string key reaches fallback routing on pinned main, and a transform returning now cannot override a deferred mapping. This read-only review did not execute those scenarios.

Is this the best way to solve the issue?

Yes: the patch repairs the existing normalization and mapping owners without adding a competing path, and preserves valid input and omitted-key behavior.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: These are bounded webhook routing and timing defects without evidence of an urgent widespread outage.
  • add merge-risk: 🚨 compatibility: Existing callers sending malformed session keys will receive 400 instead of fallback dispatch; the maintainer-authored proposal explicitly accepts this behavior.
  • 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: The supplied Repository State identifies a MEMBER author, so the external-contributor proof gate does not apply. The body reports isolated Gateway after-fix checks matching both changed owners; no authority-bearing or stored-data contract changes require additional proof.

Label justifications:

  • P2: These are bounded webhook routing and timing defects without evidence of an urgent widespread outage.
  • merge-risk: 🚨 compatibility: Existing callers sending malformed session keys will receive 400 instead of fallback dispatch; the maintainer-authored proposal explicitly accepts this behavior.
  • 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: The supplied Repository State identifies a MEMBER author, so the external-contributor proof gate does not apply. The body reports isolated Gateway after-fix checks matching both changed owners; no authority-bearing or stored-data contract changes require additional proof.

Evidence

What I checked:

  • Introduced patch: The pinned introduction delta contains only the two validation/timing repairs, their HTTP regressions, and explanatory documentation. (38e824f7e2f7)
  • Still necessary on main: The original main blob normalizes malformed session keys to undefined without rejecting them. Its transform merger recognizes only next-heartbeat overrides, so now cannot replace a deferred base action. (src/gateway/hooks.ts:641, c48607980ace)
  • Timing repair preserves validation: Both timing fields now accept either documented enum value; invalid values retain the base/default fallback and the merged action still passes through validateAction. (src/gateway/hooks-mapping.ts:413, 38e824f7e2f7)
  • Rejection precedes dispatch: The direct agent handler returns 400 immediately when normalization fails, before resolving a session or invoking agent dispatch. Existing authentication, agent allowlists, session prefixes, and configuration-generation checks remain in place. (src/gateway/server/hooks-request-handler.ts:424, 38e824f7e2f7)
  • HTTP regression coverage: Seven malformed key shapes assert HTTP 400 and no agent execution. A configured deferred mapping with a real transform module asserts immediate timing in the wake response and agent job. These are supplemental mocked-runner tests; they were inspected, not executed during this review. (src/gateway/server.hooks.test.ts:187, 38e824f7e2f7)
  • Intentional compatibility tradeoff: The supplied maintainer-authored PR explicitly accepts returning 400 for malformed keys rather than silently dispatching to fallback sessions. Valid strings and omitted keys retain their paths; the documentation explains the changed response. This accepted scope does not require another product decision. Public docs: docs/automation/cron-jobs/webhooks.md. (docs/automation/cron-jobs/webhooks.md:169, 38e824f7e2f7)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jay Zhou: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Record before/after server.hooks.test.ts benchmark results, the focused single-worker wall time, and CI seconds in the PR evidence.

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 ea4e8bc into main Oct 7, 2026
193 of 195 checks passed
@steipete
steipete deleted the fix/w10-l8 branch October 7, 2026 03:08
@steipete

steipete commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…errides (openclaw#166406)

* fix(hooks): reject malformed agent session keys

* fix(hooks): honor immediate wake transform overrides

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

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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