Skip to content

fix: rotate sessionFile after daily reset#78618

Merged
sallyom merged 1 commit intoopenclaw:mainfrom
zerone0x:fix/issue-78607
May 7, 2026
Merged

fix: rotate sessionFile after daily reset#78618
sallyom merged 1 commit intoopenclaw:mainfrom
zerone0x:fix/issue-78607

Conversation

@zerone0x
Copy link
Copy Markdown
Contributor

@zerone0x zerone0x commented May 6, 2026

Summary

  • stop reusing a persisted sessionFile when its basename no longer matches the current sessionId
  • preserve topic transcript paths that still belong to the active session
  • add regression coverage for path resolution, daily reset rotation, custom transcript preservation, and already-stale generated transcript repair

Testing

  • node scripts/test-projects.mjs --maxWorkers=1 src/config/sessions/sessions.test.ts src/auto-reply/reply/session.test.ts src/gateway/server-methods/agent.test.ts src/gateway/server.sessions.reset-models.test.ts
  • pnpm exec oxfmt --check --threads=1 CHANGELOG.md src/auto-reply/reply/session.test.ts src/config/sessions/paths.ts src/config/sessions/sessions.test.ts src/gateway/server-methods/agent.ts src/gateway/server-methods/agent.test.ts
  • git diff --check origin/main...HEAD

Real behavior proof

  • Behavior or issue addressed: Daily Gateway agent session rollover must persist a new generated transcript file when the stored generated sessionFile points at a different UUID than the current session. This covers [Bug]: Daily session reset regresses #57020 — sessionFile not rotated #78607’s stale generated transcript state.
  • Real environment tested: Disposable local OpenClaw Gateway from this PR checkout’s code diff; proof was run before the final changelog-only attribution amend, and the current head is a95a37499706ea703e0895063600861de2244c65. Isolated HOME, OPENCLAW_STATE_DIR, and OPENCLAW_CONFIG_PATH; plugins disabled; loopback token auth; no mocked session store or mocked Gateway handler.
  • Exact steps or command run after this patch: Seeded /tmp/openclaw-proof-78607/state/agents/main/sessions/sessions.json with a 26-hour-old agent:main:main entry whose sessionId was 63b16647-ea0c-4a22-808b-ce616326b445 but whose generated sessionFile basename was 685a51f7-7adf-48b1-89ca-d3ab86dd6e0f.jsonl; started pnpm openclaw gateway run --port 19107 --bind loopback --auth token --token proof-token --allow-unconfigured --ws-log compact; called the live Gateway health and agent methods through src/gateway/call.js using backend gateway-client token auth; then reread the persisted sessions store from disk.
  • Evidence after fix: Copied live terminal output from the disposable Gateway harness:
    GATEWAY_HEALTH
    {
      "ok": true,
      "channels": {},
      "channelOrder": [],
      "channelLabels": {}
    }
    
    AGENT_CALL_ERROR
    Error: Anthropic API key is missing. Configure one before running the agent.
    
    AFTER
    {
      "sessionId": "66b4b63c-f6be-4dfa-8b13-cd5aae653089",
      "sessionFile": "66b4b63c-f6be-4dfa-8b13-cd5aae653089.jsonl",
      "updatedAt": 1778117113871,
      "sessionStartedAt": 1778117113870,
      "lastInteractionAt": 1778117113870
    }
    
    ASSERTIONS
    sessionId changed: true
    sessionFile changed: true
    sessionFile matches sessionId: true
    
  • Observed result after fix: The real Gateway agent request crossed the daily rollover path, generated a new session id, and persisted sessionFile to the matching generated <new-sessionId>.jsonl path before provider execution failed due the intentionally credential-free disposable environment.
  • What was not tested: Real model completion was not tested; the bug is the Gateway session-store write that happens before provider execution, and the live Gateway call reached and proved that write.

Fixes #78607

@openclaw-barnacle openclaw-barnacle Bot added size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 6, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 6, 2026

Codex review: needs real behavior proof before merge.

Summary
The PR adds generated sessionFile rotation in the gateway agent daily rollover path, regression coverage for generated and custom transcript paths, and a changelog entry.

Reproducibility: yes. A high-confidence source reproduction is to seed agent:main:main with stale sessionStartedAt, an old sessionId, and an old generated sessionFile, then invoke the gateway agent path and observe current main generate a new sessionId while preserving the old path.

Real behavior proof
Needs real behavior proof before merge: No after-fix real gateway/session-store proof is present; contributor should add terminal output, redacted logs, a screenshot/video, recording, or linked artifact showing daily rollover persists a new generated transcript path, with private details redacted, then update the PR body for automatic re-review or ask a maintainer to comment @clawsweeper re-review.

Next step before merge
The remaining blocker is contributor/maintainer real behavior proof and normal PR gating, not a narrow code repair that automation can provide.

Security
Cleared: The diff is limited to TypeScript session path/handler logic, tests, and changelog; it adds no dependencies, workflow changes, secrets handling, downloads, or new code-execution surface.

Review details

Best possible solution:

Land the narrow gateway write-path rotation after redacted real behavior proof is added and normal CI completes.

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

Yes. A high-confidence source reproduction is to seed agent:main:main with stale sessionStartedAt, an old sessionId, and an old generated sessionFile, then invoke the gateway agent path and observe current main generate a new sessionId while preserving the old path.

Is this the best way to solve the issue?

Yes for the code direction. Rotating generated transcript filenames in the gateway rollover write path while preserving custom names is narrower than globally rejecting persisted paths, but the PR is not merge-ready without real behavior proof and completed checks.

What I checked:

  • Linked regression evidence: The linked issue reports v2026.5.4 store state where sessionId advanced after daily reset while sessionFile still pointed at an older JSONL, with no JSONL present for the current session id.
  • Current main omits sessionFile during gateway rollover: Current main builds nextEntryPatch with a new sessionId and lifecycle timestamps but does not include sessionFile before merging/persisting the row. (src/gateway/server-methods/agent.ts:1031, d3fc1985feba)
  • Merge preserves omitted fields: mergeSessionEntryWithPolicy spreads the existing entry before the patch, so an omitted sessionFile survives even when sessionId changes. (src/config/sessions/types.ts:468, d3fc1985feba)
  • PR rotates generated paths in the gateway write path: The latest patch adds resolveRotatedGeneratedSessionFilePath and includes the rotated generated path in nextEntryPatch only for new-session rollover with a previous entry. (src/gateway/server-methods/agent.ts:1030, f3cc43a56e9a)
  • Custom path preservation coverage: The patch adds tests for generated-path rotation, already-stale UUID transcript repair, and preserving custom transcript paths during gateway rollover. (src/gateway/server-methods/agent.test.ts:1814, f3cc43a56e9a)
  • Real behavior proof still missing: The PR body lists only a targeted test command, and the only PR comment remains the prior ClawSweeper request for real behavior proof; no runtime logs, terminal output, screenshot, recording, or artifact was added. (f3cc43a56e9a)

Likely related people:

  • steipete: Recent GitHub commit history shows repeated maintenance of gateway/session freshness, session usage, and session path behavior near this regression surface. (role: recent maintainer; confidence: high; commits: 566d2d73a323, 1c6911c01ff4, b0cf76165c9d; files: src/gateway/server-methods/agent.ts, src/config/sessions/paths.ts, src/config/sessions/session-file.ts)
  • vincentkoc: Recent history touches gateway agent tests and adjacent gateway/session behavior that this patch extends. (role: adjacent gateway/session maintainer; confidence: medium; commits: b8f9137d31fb, e2eb5649d1b9, 6fb9e9e5581f; files: src/gateway/server-methods/agent.test.ts, src/gateway/server-methods/agent.ts)
  • onutc: The thread-bound subagent work centralized sessionFile resolve/persist behavior now used by keyed sessions and reset-related transcript handling. (role: introduced related session-file helper behavior; confidence: medium; commits: 8178ea472db1; files: src/config/sessions/session-file.ts, src/config/sessions/paths.ts, src/auto-reply/reply/session.ts)
  • sallyom: The PR is assigned to this maintainer, and the latest branch commit specifically addresses the earlier gateway session-file review findings. (role: likely follow-up owner; confidence: medium; commits: f3cc43a56e9a; files: src/gateway/server-methods/agent.ts, src/config/sessions/paths.ts, src/gateway/server-methods/agent.test.ts)

Remaining risk / open question:

  • No after-fix real gateway/session-store behavior proof has been provided for the external PR.
  • The observed head still had in-progress CI checks, and I did not run tests locally because this was a read-only review.

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

Copy link
Copy Markdown

@byungskers byungskers left a comment

Choose a reason for hiding this comment

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

This is a solid defensive fix. Reusing a stale sessionFile after daily reset could definitely lead to transcript pollution or confusing audit trails.

The isSessionFileCompatibleWithSessionId helper is well-scoped, and keeping the topic-transcript path intact (sess-1-topic-456.jsonl) shows good attention to the edge cases. Tests cover both the rejection and the preservation cases nicely. LGTM!

@sallyom sallyom self-assigned this May 6, 2026
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label May 7, 2026
@sallyom sallyom force-pushed the fix/issue-78607 branch from 0b45017 to 374bb17 Compare May 7, 2026 00:39
@sallyom sallyom force-pushed the fix/issue-78607 branch 2 times, most recently from 3479799 to f3cc43a Compare May 7, 2026 00:45
@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels May 7, 2026
Signed-off-by: sallyom <somalley@redhat.com>
@sallyom sallyom force-pushed the fix/issue-78607 branch from f3cc43a to a95a374 Compare May 7, 2026 01:32
@sallyom sallyom merged commit bf25110 into openclaw:main May 7, 2026
117 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime proof: supplied External PR includes structured after-fix real behavior proof. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Daily session reset regresses #57020 — sessionFile not rotated

3 participants