Skip to content

feat(hooks): add persistent hook session mode - #75918

Merged
vincentkoc merged 5 commits into
openclaw:mainfrom
ryanrhughes:fix/11665-persistent-hook-sessions
Jul 29, 2026
Merged

vincentkoc merged 5 commits into
openclaw:mainfrom
ryanrhughes:fix/11665-persistent-hook-sessions

Conversation

@ryanrhughes

@ryanrhughes ryanrhughes commented May 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #11665.

Related admission work: #104712

What Problem This Solves

Hook agent calls always used isolated run sessions, so repeated webhook deliveries could not intentionally reuse conversation context even when an integration had a stable, scoped session key.

Why This Change Was Made

This adds an explicit sessionMode: "isolated" | "persistent" contract for direct and mapped hook agent runs. Isolation remains the default. Persistent runs require a stable, policy-approved session key and reuse the existing cron session:<key> target; this PR does not change the cron runner API or its general isolation behavior.

The maintainer rewrite removes the original adjacent cron/session/auth changes and keeps ownership at the hook config, mapping, request-handler, and gateway dispatch boundaries.

User Impact

Trusted webhook integrations can opt into durable multi-turn hook sessions. Existing hooks remain isolated unless they explicitly request persistent mode.

Security behavior is fail-closed:

  • Direct persistent calls require an explicit request sessionKey, hooks.allowRequestSessionKey: true, and non-empty hooks.allowedSessionKeyPrefixes.
  • Persistent mappings require a stable static key, hooks.defaultSessionKey, or a transform that resolves a key at runtime.
  • Template and transform-derived keys retain request-key and prefix policy checks.
  • sessionMode is included in replay scope, so isolated and persistent deliveries cannot share an idempotency result.

Evidence

Exact reviewed head: 016d95e340dd8c22009b6bfb0f874a8c302e4aa4

Signed contributor rewrite: 2d0b77e8c764de1619036ad405a798e71dedfe33

Signed prior current-main anchor: 36c6d4942a440cc498fd3222204868f54b5cddfc

Signed maintainer validation fix: 8496b409f067b22828eef5bf22b235a21367957a

Signed latest-main anchor: ebf34d1230b635a2e593e67a4f71ae44a3236420

Anchor baseline: e80fe942c8dae4b264acb2b501466224e842aa61

The anchor baseline contains the merged gateway admission change from #104712:

Composition with #104712 is additive: both direct and mapped requests still await dispatchAgentHookWithReplay; persistent mode only selects the existing session:<key> target after session-key policy validation. The admission tests prove simultaneous persistent duplicates share one pending admitted dispatch and retain the persistent target.

{
  "verdict": "pass",
  "headSha": "016d95e340dd8c22009b6bfb0f874a8c302e4aa4",
  "anchorBaseSha": "e80fe942c8dae4b264acb2b501466224e842aa61",
  "gatewayAdmissionMergeSha": "814b9f6e36f3b2bfcf938f905a4c63b003314598",
  "focusedTests": {
    "files": 5,
    "passed": 73,
    "failed": 0
  },
  "assertions": [
    "isolated remains the default",
    "direct persistence requires an explicit bounded request key",
    "mapped persistence requires a stable key source",
    "persistent duplicates share one pending admitted dispatch",
    "session mode separates replay scope"
  ]
}

Exact-head validation:

The current PR diff is 19 files, +569/-8, and is based on main.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M labels May 2, 2026
@clawsweeper

clawsweeper Bot commented May 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 2:25 PM ET / 18:25 UTC.

ClawSweeper review

What this changes

Adds an opt-in sessionMode: "persistent" for direct and mapped Gateway hooks so a policy-approved stable session key can retain multi-turn agent context across webhook deliveries.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for a maintainer product and security-boundary decision. The patch is a coherent, explicitly opt-in implementation with boundary-level proof, but it adds durable state reuse to public hook configuration and direct hook payloads; current main intentionally routes hook runs as isolated sessions.

Priority: P2
Reviewed head: 016d95e340dd8c22009b6bfb0f874a8c302e4aa4
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The implementation and focused boundary proof are strong, with merge readiness held only by the maintainer decision and final exact-merge validation.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR supplies after-fix loopback Gateway and runner evidence for both persistent and default-isolated paths, using a mocked provider but the real HTTP dispatch and session-selection boundaries.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR supplies after-fix loopback Gateway and runner evidence for both persistent and default-isolated paths, using a mocked provider but the real HTTP dispatch and session-selection boundaries.
Evidence reviewed 5 items Current-main behavior: Current main does not define hook sessionMode; its hook dispatch constructs an isolated session target, preserving the documented default that repeated hook deliveries do not reuse conversation context.
Configuration contract: Current main exposes mapping sessionKey, request-key admission, and optional prefixes, but no mode for reusing the resolved session; the PR adds a new public mode rather than repairing an already-supported behavior.
Branch proof: The PR’s exact-head proof exercises real loopback Gateway HTTP dispatch and the runner/session boundary for direct and mapped persistent requests, default isolated requests, replay separation, and concurrent admission; the provider is mocked to keep the proof credential-free.
Findings None None.
Security None None.

How this fits together

Gateway hooks accept authenticated HTTP webhook requests, validate their routing and session-key policy, then schedule an agent run through the cron-isolated runner. The runner’s session target determines whether the delivery starts a fresh context or resumes a stored conversation.

flowchart LR
  Webhook[Webhook delivery] --> Gateway[Gateway hook endpoint]
  Gateway --> Policy[Session-key policy validation]
  Policy --> Mapping[Direct or mapped hook action]
  Mapping --> Dispatch[Agent-run dispatch]
  Dispatch --> Target{Session target}
  Target --> Isolated[Fresh isolated session]
  Target --> Persistent[Existing keyed session]
  Persistent --> Agent[Agent context and response]
Loading

Decision needed

Question Recommendation
Should OpenClaw expose persistent webhook sessions through sessionMode: "persistent" on direct and mapped hooks, using the submitted request-key and prefix policy as the long-term security boundary? Approve explicit persistence: Merge the opt-in mode after final merge-result validation, retaining isolated sessions as the default and the prefix-bound policy for direct requests.

Why: This is a new public capability and configuration contract that intentionally changes which persisted agent state a trusted webhook can resume; correctness tests cannot choose the repository’s desired authorization and operator model.

Before merge

  • Resolve merge risk (P1) - Merging introduces persistent conversation state behind a public hook configuration and request payload mode; operators need a clear long-term decision that prefix-bounded hook credentials are the intended authorization boundary for targeting durable sessions.
  • Resolve merge risk (P1) - The PR is mergeable but behind current main, and several exact-head checks were still running in the supplied state; final merge proof should cover the actual merge result, including the direct and mapped admission/replay paths.
  • Complete next step (P2) - No mechanical repair is indicated; a maintainer must accept or reject the new public persistent-session and authorization contract before merge.
Agent review details

Security

None.

PR surface

Source +84, Tests +466, Docs +11, Generated 0. Total +561 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 9 86 2 +84
Tests 5 466 0 +466
Docs 3 14 3 +11
Config 0 0 0 0
Generated 2 3 3 0
Other 0 0 0 0
Total 19 569 8 +561

Review metrics

Metric Value Why it matters
Persistent-session surface 1 new mode across 2 hook ingress paths The same public sessionMode contract affects both direct /hooks/agent payloads and mapped hook configuration, so a single policy decision governs two operator entry points.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/server.hooks-session-mode.test.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #11665
Summary: This PR is the explicitly linked candidate implementation for the open request to make stable hook keys capable of intentional multi-turn session reuse.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Approve the opt-in contract, then refresh proof (recommended)
    Confirm that trusted hook credentials plus allowed key prefixes are the intended durable-session boundary, then rebase or merge-test the exact resulting head and rerun the focused hook proof.
  2. Keep the existing isolated-only behavior
    Reject the new public persistence mode if hook credentials should never be able to resume durable agent context, even with explicit prefixes.
  3. Pause for a narrower session-policy design
    Pause this PR if maintainers want a distinct hook-session ownership model rather than extending the current request-key policy.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
After maintainer approval, refresh the branch against current main and run the focused direct/mapped persistent-session and admission/replay proof on the exact mergeable head.

Technical review

Best possible solution:

Adopt the explicit opt-in mode only if maintainers accept its prefix-bound hook-key policy as the permanent boundary, then revalidate the rebased merge result with fresh-install and upgrade-safe configuration coverage.

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

Yes, from source: current main constructs hook jobs with an isolated session target, so repeated stable hook keys do not select a reusable agent session. The supplied PR proof then exercises the changed Gateway-to-runner boundary, although this review did not run a live provider.

Is this the best way to solve the issue?

Unclear. The explicit isolated-versus-persistent mode is the narrowest implementation shape found and avoids changing existing defaults, but maintainers must first decide whether the proposed hook-key policy is the right permanent authorization model for durable state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 97d374b357eb.

Labels

Label justifications:

  • P2: This is a bounded but meaningful Gateway capability addition whose effects are limited to operators that opt in.
  • merge-risk: 🚨 compatibility: The PR adds public configuration and request-payload behavior that operators may adopt and expect to remain stable across upgrades.
  • merge-risk: 🚨 session-state: Persistent mode changes hook runs from fresh sessions to reuse of stored agent context and transcript state.
  • merge-risk: 🚨 security-boundary: A trusted hook caller can select durable session continuity only through the proposed request-key and prefix authorization policy.
  • 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 supplies after-fix loopback Gateway and runner evidence for both persistent and default-isolated paths, using a mocked provider but the real HTTP dispatch and session-selection boundaries.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies after-fix loopback Gateway and runner evidence for both persistent and default-isolated paths, using a mocked provider but the real HTTP dispatch and session-selection boundaries.

Evidence

What I checked:

  • Current-main behavior: Current main does not define hook sessionMode; its hook dispatch constructs an isolated session target, preserving the documented default that repeated hook deliveries do not reuse conversation context. (src/gateway/server/hooks.ts:203, 97d374b357eb)
  • Configuration contract: Current main exposes mapping sessionKey, request-key admission, and optional prefixes, but no mode for reusing the resolved session; the PR adds a new public mode rather than repairing an already-supported behavior. (src/config/types.hooks.ts:1, 97d374b357eb)
  • Branch proof: The PR’s exact-head proof exercises real loopback Gateway HTTP dispatch and the runner/session boundary for direct and mapped persistent requests, default isolated requests, replay separation, and concurrent admission; the provider is mocked to keep the proof credential-free. (src/gateway/server.hooks-session-mode.test.ts:1, 016d95e340dd)
  • Related canonical request: The linked open feature request describes the same observable gap: a stable hook session key currently identifies routing metadata but does not retain prior conversation context. This PR is its explicit candidate implementation. (src/cron/isolated-agent/run.ts:1, 97d374b357eb)
  • Recent adjacent provenance: The merged Gateway admission work established the current dispatch-and-replay boundary that this branch composes with; its merge commit is included in the PR’s declared base ancestry. (src/gateway/server/hooks-request-handler.ts:1, 814b9f6e36f3)

Likely related people:

  • coolmanns: Authored the merged Gateway hook-admission change that owns the request admission and replay boundary this feature must preserve. (role: recent gateway contributor; confidence: medium; commits: 814b9f6e36f3; files: src/gateway/server/hooks-request-handler.ts, src/gateway/server/hooks.ts)
  • vincentkoc: Authored the branch’s persistent-mapping validation follow-up and current-main alignment commits, indicating direct familiarity with this feature’s config and session-policy shape. (role: recent design contributor; confidence: medium; commits: 8496b409f067, ebf34d1230b6; files: src/config/zod-schema.root-shape.ts, src/gateway/server/hooks-request-handler.ts)

Rank-up moves

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

  • Obtain an explicit maintainer decision on the persistent hook-session policy.
  • Refresh the exact mergeable head and rerun the focused direct/mapped session and admission proof.

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 (2 earlier review cycles)
  • reviewed 2026-07-03T21:06:24.701Z sha 752d03a5889318112716d9cbd1e2d4ef22d59e89 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-29T17:55:46.650Z sha ebf34d1 :: needs maintainer review before merge. :: none

@ryanrhughes
ryanrhughes force-pushed the fix/11665-persistent-hook-sessions branch 2 times, most recently from 3a9c98b to 597205b Compare May 2, 2026 03:25
@ryanrhughes
ryanrhughes force-pushed the fix/11665-persistent-hook-sessions branch from 597205b to d3fc3f6 Compare May 6, 2026 20:59
@ryanrhughes
ryanrhughes requested review from a team as code owners May 6, 2026 20:59
@openclaw-barnacle openclaw-barnacle Bot added triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. channel: bluebubbles Channel integration: bluebubbles channel: discord Channel integration: discord channel: googlechat Channel integration: googlechat channel: imessage Channel integration: imessage channel: line Channel integration: line channel: matrix Channel integration: matrix channel: mattermost Channel integration: mattermost channel: msteams Channel integration: msteams channel: nextcloud-talk Channel integration: nextcloud-talk channel: nostr Channel integration: nostr channel: signal Channel integration: signal channel: slack Channel integration: slack channel: telegram Channel integration: telegram channel: tlon Channel integration: tlon channel: voice-call Channel integration: voice-call channel: whatsapp-web Channel integration: whatsapp-web channel: zalo Channel integration: zalo channel: zalouser Channel integration: zalouser and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 6, 2026
@benjaminwood

Copy link
Copy Markdown

Thank you for this ryan. I know your last one went stale and was automatically closed. I hope this one makes it into a release!

@clawsweeper

clawsweeper Bot commented May 22, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper PR egg

🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat.

Where did the egg go?
  • The egg game starts only after the PR passes the real-behavior proof check.
  • Before that, no creature or rarity is rolled. The treat waits for real proof.
  • This is still just collectible flavor: proof affects review readiness, not creature quality.

@ryanrhughes

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Added stronger real behavior proof to the PR body:

  • gateway HTTP hook dispatch proof for direct and mapped sessionMode: "persistent"
  • runner proof that persistent hook runs call session resolution with forceNew: false and reuse the stored session key/id
  • runner proof that omitted/default mode stays isolated with run-scoped session keys across repeated runs

The model call is mocked in the proof run so the evidence stays credential-free, but the gateway listener and hook HTTP dispatch path are real.

@clawsweeper

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

@ryanrhughes

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Jun 5, 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:

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

ryanrhughes and others added 5 commits July 29, 2026 19:12
* commit 'a47d81e7b33bf89c316a6aba857fafb0d5924167':
  fix(ui): derive cron timezone suggestions (openclaw#115973)
* commit 'e80fe942c8dae4b264acb2b501466224e842aa61':
  fix(gateway): stop start-time repair from retargeting managed services (openclaw#115935)
  fix(plugins): scope Codex relay with tool matchers (openclaw#109603)
  fix(discord): bound webhook send body reads (openclaw#109076)
  fix(ui): preserve initials for missing user avatars (openclaw#115976)
  feat(ui): add provider icons to coding catalogs (openclaw#115956)
  fix(daemon): refuse duplicate launchd gateway managers (openclaw#97285)
  fix(memory-lancedb): share the recall cooldown with the auto-recall prompt-build hook (openclaw#112927)
  fix(test): isolate plugin install fixtures (openclaw#116008)
  fix(feishu): guard Object.assign against prototype pollution in webhook payload merge (openclaw#111729)
  fix(sms): isolate validated webhook quotas per sender (openclaw#104862)
  fix(sessions): recover deleted chats without endless retries (openclaw#115974)
  fix(restart): log errors from restart hook callbacks instead of swallowing (openclaw#108847)
  feat(ui): enable tool-loop detection from Labs (openclaw#115983)
  fix(telegram): catch unhandled rejections in webhook and ingress worker shutdown (openclaw#100998)
  fix(memory): keep rollbacks compatible after recall metadata upgrade (openclaw#116003)
@vincentkoc

Copy link
Copy Markdown
Member

maintainer decision: accepted.

the opt-in sessionMode: "persistent" contract is acceptable with isolated sessions remaining the default. trusted hook credentials plus configured allowed session-key prefixes are the intended authorization boundary for selecting durable hook sessions.

the exact head has fresh direct/mapped persistence, default-isolation, replay/admission proof and a green CI gate. proceeding through the repository prepare/merge validation.

@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

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 feature: ✨ showcase ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L stale Marked as stale due to inactivity 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.

[Feature]: Webhook hook sessions should reuse existing session when sessionKey is consistent (multi-turn support)

3 participants