Skip to content

fix(cron): allow webhook isolated runs to reuse sessionKey sessions - #70895

Closed
dannylin108 wants to merge 2 commits into
openclaw:mainfrom
dannylin108:codex/fix-stale-issue-in-forked-repo
Closed

dannylin108 wants to merge 2 commits into
openclaw:mainfrom
dannylin108:codex/fix-stale-issue-in-forked-repo

Conversation

@dannylin108

Copy link
Copy Markdown

Motivation

  • Isolated cron runs always forced a fresh session which discarded context even for /hooks/agent webhook calls that intentionally provide stable sessionKey values or externalContentSource; this caused unwanted session rollovers and lost history.

Description

  • Compute forceNewSession in src/cron/isolated-agent/run.ts and only force a fresh session when sessionTarget === "isolated" and the run is not hook/webhook-sourced, preserving hook sessions when externalContentSource or hook:* session keys are present.
  • Update src/cron/isolated-agent/run.skill-filter.test.ts to add a regression test that verifies webhook-sourced isolated runs pass forceNew: false to resolveCronSession while keeping the existing isolated-cron behavior.
  • Modified files: src/cron/isolated-agent/run.ts, src/cron/isolated-agent/run.skill-filter.test.ts.

Testing

  • Ran the targeted tests with pnpm test src/cron/isolated-agent/run.skill-filter.test.ts src/cron/isolated-agent/session.test.ts and the suite passed.
  • Test output: 2 test files ran, 27 tests passed (all green).

Fixes #70894

@greptile-apps

greptile-apps Bot commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a session rollover bug in isolated cron runs by computing forceNewSession conditionally — forcing a new session only when sessionTarget === \"isolated\" and the run is not hook/webhook-sourced. The logic correctly falls back to the pre-existing behavior for all non-hook isolated runs and a regression test is added.

Confidence Score: 5/5

Safe to merge — the change is minimal, well-tested, and preserves existing behavior for non-hook isolated runs.

The logic change is a single two-line conditional that correctly scopes the session-force behavior. The new test covers the key regression case, and all 27 existing tests continue to pass. No data-loss or auth boundary risk is introduced.

No files require special attention.

Reviews (1): Last reviewed commit: "fix(cron): reuse hook sessions for isola..." | Re-trigger Greptile

@clawsweeper

clawsweeper Bot commented Apr 27, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

This PR should close because it is the implicit hook-session-persistence variant of a real webhook session-continuity problem, and the remaining work is already owned by the canonical issue plus the explicit sessionMode implementation path.

Root-cause cluster
Relationship: superseded
Canonical: #11665
Summary: This PR overlaps the persistent webhook hook-session problem but uses an implicit persistence approach; the canonical issue and explicit sessionMode PR own the remaining work.

Members:

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

Canonical path: Keep persistent hook-session work on the explicit sessionMode path, preserving isolated default behavior and requiring security-boundary proof before merge.

So I’m closing this here because the remaining work is already tracked in the canonical issue.

Review details

Best possible solution:

Keep persistent hook-session work on the explicit sessionMode path, preserving isolated default behavior and requiring security-boundary proof before merge.

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

Yes, source-level. Current main dispatches hook-agent requests as isolated cron jobs, passes forceNew=true, and resolveCronSession only reuses existing session ids when forceNew is false.

Is this the best way to solve the issue?

No. This PR is a plausible minimal patch, but the best fix is an explicit persistent hook-session mode that preserves default isolation and keeps the trust boundary reviewable.

Security review:

Security review needs attention: Needs attention: the diff changes the hook session-key trust boundary by making durable reuse implicit for hook-sourced isolated runs.

  • [medium] Implicit hook session persistence — src/cron/isolated-agent/run.ts:470
    Hook-sourced requests can become durable transcript selectors based on source/key shape alone, which changes the external hook session-key trust boundary without an explicit trusted persistence mode.
    Confidence: 0.88

AGENTS.md: found and applied where relevant.

What I checked:

  • Repository policy applied: Root AGENTS.md was read fully; its session-state, compatibility, security-boundary, and release-owned changelog guidance affected this PR review. (AGENTS.md:29, 8ed6c78b7891)
  • Scoped gateway policy checked: The scoped gateway AGENTS.md was read because the hook dispatch path is part of the reviewed behavior. (src/gateway/AGENTS.md:1, 8ed6c78b7891)
  • Current hook dispatch remains isolated: Current main builds direct hook-agent requests as synthetic CronJob objects with sessionTarget: "isolated" before calling the isolated cron runner. (src/gateway/server/hooks.ts:128, 8ed6c78b7891)
  • Current runner still forces new isolated sessions: Current main passes forceNew: input.job.sessionTarget === "isolated" into resolveCronSession, so the source-level user problem is still real on main. (src/cron/isolated-agent/run.ts:648, 8ed6c78b7891)
  • Session reuse is already gated by forceNew: resolveCronSession only reuses a stored entry.sessionId when !params.forceNew; otherwise the isolated path rolls to a new session id. (src/cron/isolated-agent/session.ts:129, 8ed6c78b7891)
  • Current hook API lacks explicit persistence mode: Current main exposes hook payload and dispatch fields for sessionKey and external-content provenance, but no sessionMode, reuseSession, or equivalent opt-in. (src/gateway/hooks.ts:221, 8ed6c78b7891)

Likely related people:

  • steipete: Live file history shows recent work on cron session targets and hook/gateway surfaces, and prior review discussion selected the explicit sessionMode direction as the safer path. (role: recent area contributor and reviewer; confidence: medium; commits: be5906e19dd7, f24ae91842d6, 236bd42bb36c; files: src/cron/isolated-agent/run.ts, src/gateway/server/hooks.ts, src/gateway/hooks-mapping.ts)
  • ryanrhughes: Authored the earlier and current explicit sessionMode implementations that are directly related to the canonical persistent hook-session path. (role: canonical implementation proposer; confidence: high; commits: 632de9a1bd46, 752d03a58893; files: src/config/types.hooks.ts, src/config/zod-schema.hooks.ts, src/gateway/hooks-mapping.ts)
  • pgondhi987: Authored the current allowRequestSessionKey gate for template-rendered hook mapping session keys, adjacent to the trust boundary this PR changes. (role: adjacent hook session-key policy contributor; confidence: medium; commits: 5275d008ed33; files: src/gateway/hooks-mapping.ts, src/gateway/hooks.ts)
  • obviyus: Recent cron session-target work changed detached session-target behavior near the force-new decision point this PR must reconcile with. (role: recent adjacent cron/session contributor; confidence: medium; commits: bc7f9a36ec55; files: src/cron/isolated-agent/run.ts)

Codex review notes: model internal, reasoning high; reviewed against 8ed6c78b7891.

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

To use Codex here, create an environment for this repo.

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 10, 2026
@dannylin108

Copy link
Copy Markdown
Author

Added the requested changelog entry under Unreleased -> Fixes and pushed it on the PR branch in commit 4c1c1c4241.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels May 20, 2026
@clawsweeper

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

@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.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jun 7, 2026
@clawsweeper clawsweeper Bot added rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 7, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Jun 13, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed rating: 🌊 off-meta tidepool PR readiness rating does not apply to this item. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 13, 2026
@clawsweeper clawsweeper Bot added status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. P2 Normal backlog priority with limited blast radius. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. labels Jun 17, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Jun 21, 2026
@steipete steipete closed this Jul 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Regression: Webhook agent runs always start a new session regardless of sessionKey / session config

2 participants