Skip to content

fix(gateway): invalidate bootstrap cache on session rollover#38535

Merged
Takhoffman merged 2 commits intoopenclaw:mainfrom
yfge:fix/issue-38494-clear-bootstrap-cache-on-reset
Mar 7, 2026
Merged

fix(gateway): invalidate bootstrap cache on session rollover#38535
Takhoffman merged 2 commits intoopenclaw:mainfrom
yfge:fix/issue-38494-clear-bootstrap-cache-on-reset

Conversation

@yfge
Copy link
Copy Markdown
Contributor

@yfge yfge commented Mar 7, 2026

Background

Session bootstrap files are cached per sessionKey, but daily/idle rollovers mint a new sessionId while keeping the same key. That left stale AGENTS.md/MEMORY.md/USER.md snapshots in memory until gateway restart (see #38494).

Changes

  • Clear bootstrap snapshots whenever a session rolls over to a new sessionId in the main auto-reply session init path (initSessionState).
  • Apply the same invalidation in command-driven session resolution (resolveSession) and isolated cron session resolution (resolveCronSession) so all rollover paths are consistent.
  • Add/extend tests to assert:
    • stale daily reset invalidates snapshot
    • fresh session reuse does not invalidate snapshot
    • stale/forceNew cron rollovers invalidate snapshot

Validation

  • Added assertions in:
    • src/auto-reply/reply/session.test.ts
    • src/cron/isolated-agent/session.test.ts
  • Could not run full test suite in this environment because package manager tooling is unavailable (pnpm missing and npx vitest cannot resolve workspace deps).

Impact

  • Workspace bootstrap files are reloaded after daily/idle/forced session rollover without requiring gateway restart.
  • No behavior change for fresh-session reuse path.

Fixes #38494

@openclaw-barnacle openclaw-barnacle bot added commands Command implementations size: XS labels Mar 7, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 7, 2026

Greptile Summary

This PR fixes a stale-cache bug (#38494) where bootstrap snapshot files remained in memory after a session rolled over to a new ID on daily/idle/forced resets. The fix adds clearBootstrapSnapshot(sessionKey) calls in the three session-resolution paths — auto-reply, command-driven, and cron — and extends tests for two of those paths.

  • The cache-invalidation logic is correctly placed in all three files: it fires only when a prior session ID is confirmed and a new one is about to be minted, so there is no spurious invalidation for fresh-session reuse.
  • Tests are added for the auto-reply and cron paths, but the equivalent behaviour in resolveSession (src/commands/agent/session.ts) is not covered by any test in src/commands/agent/session.test.ts (which currently only exercises resolveSessionKeyForRequest).
  • No other logic regressions observed.

Confidence Score: 4/5

  • Safe to merge; the fix is targeted, the logic is sound, and the only gap is missing test coverage for one of three changed paths.
  • The cache-invalidation logic is correct across all three code paths and aligns with the existing session-rollover semantics. Tests validate two of the three paths. The untested resolveSession path in src/commands/agent/session.ts is straightforward and low-risk, but the absence of a test is a minor gap worth addressing before merge.
  • src/commands/agent/session.ts — the new clearBootstrapSnapshot call in resolveSession has no corresponding test.

Last reviewed commit: 54eb998

Comment on lines +148 to +150
if (isNewSession && sessionEntry?.sessionId && sessionKey) {
clearBootstrapSnapshot(sessionKey);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing test coverage for this path

The PR adds clearBootstrapSnapshot to resolveSession in this file, but src/commands/agent/session.test.ts only tests resolveSessionKeyForRequest — there are no tests for resolveSession at all. The other two changed files (auto-reply/reply/session.ts and cron/isolated-agent/session.ts) each have corresponding assertions, but this path is left without any test verifying that clearBootstrapSnapshot is called on a stale session rollover or that it is not called when the session is fresh. This leaves a gap in the regression protection that the PR sets out to add.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/agent/session.ts
Line: 148-150

Comment:
**Missing test coverage for this path**

The PR adds `clearBootstrapSnapshot` to `resolveSession` in this file, but `src/commands/agent/session.test.ts` only tests `resolveSessionKeyForRequest` — there are no tests for `resolveSession` at all. The other two changed files (`auto-reply/reply/session.ts` and `cron/isolated-agent/session.ts`) each have corresponding assertions, but this path is left without any test verifying that `clearBootstrapSnapshot` is called on a stale session rollover or that it is **not** called when the session is fresh. This leaves a gap in the regression protection that the PR sets out to add.

How can I resolve this? If you propose a fix, please make it concise.

@Takhoffman Takhoffman force-pushed the fix/issue-38494-clear-bootstrap-cache-on-reset branch from 54eb998 to c7a289a Compare March 7, 2026 05:33
@openclaw-barnacle openclaw-barnacle bot added agents Agent runtime and tooling size: S and removed size: XS labels Mar 7, 2026
@Takhoffman Takhoffman force-pushed the fix/issue-38494-clear-bootstrap-cache-on-reset branch from c7a289a to 830e974 Compare March 7, 2026 05:40
@Takhoffman Takhoffman merged commit 2e31aea into openclaw:main Mar 7, 2026
28 of 29 checks passed
@Takhoffman
Copy link
Copy Markdown
Contributor

PR #38535 - fix(gateway): invalidate bootstrap cache on session rollover (#38535)

Merged after verification.

  • Merge commit: 2e31aea
  • Verified: pnpm install --frozen-lockfile, pnpm build, pnpm check, pnpm test:macmini
  • Autoland updates:
    M CHANGELOG.md
    M src/agents/bootstrap-cache.ts
    M src/auto-reply/reply/session.test.ts
    M src/auto-reply/reply/session.ts
    M src/commands/agent/session.ts
    M src/cron/isolated-agent/session.test.ts
    M src/cron/isolated-agent/session.ts
  • Rationale:
    Clear cached bootstrap snapshots whenever an existing session key rolls to a new session ID so workspace bootstrap files reload after daily, idle, and forced session resets.
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 7, 2026
* main: (45 commits)
  chore: update dependencies except carbon
  test(memory): make mcporter EINVAL retry test deterministic
  refactor(extensions): reuse shared helper primitives
  refactor(core): extract shared dedup helpers
  fix(ci): re-enable detect-secrets on main
  docs: reorder 2026.3.7 changelog highlights
  chore: bump version to 2026.3.7
  fix(android): align run command with app id
  docs: add changelog entry for Android package rename (openclaw#38712)
  fix(android): rename app package to ai.openclaw.app
  fix(gateway): stop stale-socket restarts before first event (openclaw#38643)
  fix(gateway): skip stale-socket restarts for Telegram polling (openclaw#38405)
  fix(gateway): invalidate bootstrap cache on session rollover (openclaw#38535)
  docs: update changelog for reply media delivery (openclaw#38572)
  fix: contain final reply media normalization failures
  fix: contain block reply media failures
  fix: normalize reply media paths
  Fix owner-only auth and overlapping skill env regressions (openclaw#38548)
  fix(feishu): disable block streaming to prevent silent reply drops (openclaw#38422)
  fix: suppress ACP NO_REPLY fragments in console output (openclaw#38436)
  ...
mcaxtr pushed a commit to mcaxtr/openclaw that referenced this pull request Mar 7, 2026
…w#38535)

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: yfge <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
joshavant pushed a commit that referenced this pull request Mar 7, 2026
Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: yfge <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
vincentkoc pushed a commit to BryanTegomoh/openclaw-fork that referenced this pull request Mar 8, 2026
…w#38535)

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: yfge <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
Saitop pushed a commit to NomiciAI/openclaw that referenced this pull request Mar 8, 2026
…w#38535)

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: yfge <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
jenawant pushed a commit to jenawant/openclaw that referenced this pull request Mar 10, 2026
…w#38535)

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: yfge <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
…w#38535)

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: yfge <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
senw-developers pushed a commit to senw-developers/va-openclaw that referenced this pull request Mar 17, 2026
…w#38535)

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: yfge <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
V-Gutierrez pushed a commit to V-Gutierrez/openclaw-vendor that referenced this pull request Mar 17, 2026
…w#38535)

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: yfge <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 20, 2026
…w#38535)

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: yfge <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
(cherry picked from commit 2e31aea)
alexey-pelykh pushed a commit to remoteclaw/remoteclaw that referenced this pull request Mar 20, 2026
…w#38535)

Verified:
- pnpm install --frozen-lockfile
- pnpm build
- pnpm check
- pnpm test:macmini

Co-authored-by: yfge <[email protected]>
Co-authored-by: Tak Hoffman <[email protected]>
(cherry picked from commit 2e31aea)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Daily session reset does not clear bootstrap file cache — workspace files become stale

2 participants