ISSUE DESCRIPTION Isolated cron runs leak context when they reuse a stable session key…
- User
ISSUE DESCRIPTION
Isolated cron runs leak context when they reuse a stable session key
Different isolated cron runtime sessions that reuse a stable session key must not share active LCM context. Prior runs remain archived, compaction within the current run still works, and ordinary non-cron session continuity is unchanged.
Interface
No new public interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /lossless-claw, current file: none) bash-$
- Assistant
I’ll first map the repository and search for cron/session-key/LCM context handling. Then I’ll reproduce the leak with the closest existing tests, identify where runtime identity is incorrectly conflated with the stable session key, patch it, and run focused plus broader tests.
- Assistant
The repository already contains recent rollover-hardening changesets, so I’ll inspect those and the engine’s conversation resolution path before writing a reproduction. This issue likely concerns choosing the active
conversationsrow when the host gives a new cron runtimesessionIdbut reuses its stablesessionKey. - Assistant
The existing guard deliberately refuses to split when both old and new transcript files still exist (“ambiguous rollover”), which preserves ordinary continuity but causes exactly the cron leak if isolated runs use fresh runtime IDs/files with a stable key. I’ll now inspect hook parameter types and the full guard/call sites to find a reliable internal cron discriminator rather than treating every runtime-ID change as isolated.
- Assistant
A promising discriminator is already exposed by the host bridge:
contextMode?: "isolated" | "fork". I’ll trace how that reaches engine lifecycle methods. If it is currently dropped, the minimal fix is to carry this existing private hook metadata into rollover resolution and force archival/replacement only for cron + isolated, leaving non-cron behavior untouched. - Assistant
contextModeapplies only to subagent spawning and is not supplied to context-engine bootstrap/assemble hooks, so it cannot identify cron runs here. The session key itself is the available discriminator: OpenClaw cron lanes are canonicallyagent:<agent>:cron:<job...>, and the issue explicitly scopes the behavioral change to isolated cron runtimes. I’ll inspect the existing rollover regression tests and conversation replacement semantics, then add the smallest internal cron-key predicate and invoke replacement when a keyed cron run changes runtime ID. - Assistant
Replacement archives rather than deletes, satisfying prior-run retention. The existing queue is keyed by stable key, so rollover and same-run compaction remain serialized. I’ll inspect exact bootstrap/assemble/afterTurn control flow and test helpers to ensure rotation happens before any old context can be read, and to decide whether one centralized helper can cover all three phases without interfering with lifecycle callbacks.
- Assistant
The three paths already call stale/ambiguous detection before resolving the active conversation. I’ll modify the stale-rotation helper so that a runtime-ID change on a canonical cron key is itself sufficient evidence of an isolated run boundary—even if the archived run’s transcript still exists. Because the helper runs first, existing ambiguous logic becomes a no-op after replacement. I’ll also verify whether assemble passes a session file; if not, the runtime/key pair is still enough for cron.
- Assistant
One subtlety:
applySessionReplacementcan no-op for an “already fresh” old conversation, even when it belongs to a different cron runtime. That optimization is correct for duplicate lifecycle hooks but wrong for isolated runtime identity. I’ll add a dedicated internal cron rollover branch that always archives the differing active row and creates (or defers creating) the replacement, rather than relying on the fresh-lifecycle no-op. Then I’ll exercise bootstrap, assemble, afterTurn, archive retention, and same-runtime continuity through existing public methods. - Assistant
I’ll implement the predicate narrowly (
agent:<nonempty>:cron:<nonempty...>) and put the cron branch before transcript-checkpoint requirements. For a differing runtime ID it will archive directly, then create according to the caller’s existingcreateReplacementpolicy. This preserves archived data, prevents assemble from resolving the old active row, and lets bootstrap/afterTurn establish only the new run’s context. I’ll also add the required patch changeset (release metadata, not a test). - Assistant
The environment lacks Python, so no source change was made. I’ll perform the same deterministic replacements with Node, first confirming the exact constant text.
- Assistant
The first patch addresses all read paths, but I need to check direct ingestion ordering. If the host can call
ingestbefore bootstrap/assemble,getOrCreateConversationwould still mutate the old row’s runtime ID and bypass the boundary guard. I’ll inspect those methods and either guard direct writes too or establish from the context-engine lifecycle contract that they are unreachable first. Robustness favors guarding them internally if this can be done without changing interfaces. - Assistant
Direct
ingestis public and can indeed be the first operation, so it must participate in the boundary rule. I’ll guard both single and batch ingestion once per queued operation. This also ensures that after the first message establishes the new active row, subsequent messages and compaction stay in that row. I’ll avoid guarding internalingestSingle, because afterTurn/bootstrap call it repeatedly and the public/outer reconciliation paths already establish identity. - Assistant
Type checking passes. To reproduce without adding a repository test, I’ll create a temporary TypeScript harness under
/tmpand run it through the installed Vite/Vitest transform tooling if available. The harness will use public engine/store methods to seed run 1, start run 2 with the same cron key and a different runtime ID while run 1’s transcript still exists, and assert: old row archived, new row active, no old assembled text, new-run ingestion continuity, and old messages retained. - Assistant
The engine test helpers are private, but production config resolution can supply defaults. I’ll build a small standalone harness with only the required dependency stubs and a temp database. It will use
ingestas the boundary operation (the path that previously reproduced the leak by reassigning the old active row), then verify assemble and archival directly. - Assistant
The default config ignores cron sessions, so the harness will explicitly enable this cron lane as affected deployments do. I’ll run the pre-fix behavior conceptually against the known
getOrCreateConversationlogic (it would update the old row’ssession_id), then run the patched code and assert the opposite. - Assistant
The standalone reproduction passes: run 1 remains archived with its message, run 2 gets a distinct active conversation containing only run-2 data, assemble excludes the run-1 marker, and additional operations under run 2 preserve continuity.
Next I’ll run the full engine test file. This is especially important because it contains non-cron stable-key runtime rollover tests; they must continue to fail closed/continue exactly as before. Then I’ll run the broader suite and build.
- Assistant
The focused suite found one intentional semantic conflict: an old regression test uses a cron-shaped key while asserting continuity across changed runtime IDs. That is precisely the behavior this issue changes for isolated cron runs, so its expectation is now obsolete under the issue statement; all 316 other engine tests passed, including non-cron continuity. Per instructions I won’t modify the test.
However, I’ll inspect that fixture to ensure it is genuinely cron-shaped and not revealing an overbroad match. Then I’ll run focused non-cron rollover tests and the rest of the suite separately, followed by build.
- Assistant
Correction: the failing fixture uses
agent:main:main, not cron, so it is not an expected semantic change. Its transcript paths are never written, which activates the repository’s pre-existing “missing tracked transcript” fallback. To determine whether my changes caused this or the uploaded baseline is already inconsistent with that older expectation, I’ll temporarily restore onlysrc/engine.ts, run this single test, and restore my patched file immediately afterward. This is a controlled baseline comparison; no test files will be changed. - Assistant
Baseline passes, so my public-ingest guard exposed the general missing-transcript rollover heuristic during an internal afterTurn call and changed ordinary continuity. The fix is straightforward: invoke the new ingest guard only for canonical cron keys. Non-cron ingestion then follows its exact prior path, while cron’s direct-ingest first-operation case remains covered. I’ll make that narrowing and rerun the failing continuity test plus the reproduction.
- Assistant
The ordinary non-cron continuity regression now passes again, as do typecheck and build. The narrowing does not alter the cron branch used by the successful reproduction. I’ll now rerun the complete engine suite (expected 317/317) and then the complete repository suite to confirm the earlier single failure is gone.
- Assistant
All 317 engine tests and all 1,067 repository tests pass. Before finalizing, I’ll clean up the private helper name/documentation so it accurately describes both boundary signals (isolated cron runtime change and missing transcript), review the final diff/status for unintended files, and rerun typecheck/diff checks after the mechanical rename.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.