From 7127fe053fe47758f7e4663cf3a00501f6f8e797 Mon Sep 17 00:00:00 2001 From: 0xDevNinja Date: Wed, 17 Jun 2026 12:22:56 +0530 Subject: [PATCH] fix(session): anchor system prompt date to session-start time SystemPrompt.environment() was calling new Date().toDateString() on every LLM request. applyCaching() marks the first two system messages with cacheControl, so the date lived inside the cached prefix. Any session crossing local midnight triggered a full cache miss and re-billed the entire system block as a write instead of a read. Pass the session's creation timestamp to environment() and derive Today's date from that instead. The cached system prefix now contains a date that is stable for the lifetime of the session, so the cache-busting midnight rollover no longer occurs. Fixes #32622 --- packages/opencode/src/session/prompt.ts | 2 +- packages/opencode/src/session/system.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/opencode/src/session/prompt.ts b/packages/opencode/src/session/prompt.ts index b3f85c813f20..bd1d453c971e 100644 --- a/packages/opencode/src/session/prompt.ts +++ b/packages/opencode/src/session/prompt.ts @@ -1326,7 +1326,7 @@ export const layer = Layer.effect( const [skills, env, instructions, modelMsgs] = yield* Effect.all([ sys.skills(agent), - sys.environment(model), + sys.environment(model, session.time.created), instruction.system().pipe(Effect.orDie), MessageV2.toModelMessagesEffect(msgs, model), ]) diff --git a/packages/opencode/src/session/system.ts b/packages/opencode/src/session/system.ts index 74401779d353..dd4f4fcc7f2d 100644 --- a/packages/opencode/src/session/system.ts +++ b/packages/opencode/src/session/system.ts @@ -39,7 +39,7 @@ export function provider(model: Provider.Model) { } export interface Interface { - readonly environment: (model: Provider.Model) => Effect.Effect + readonly environment: (model: Provider.Model, sessionCreated?: number) => Effect.Effect readonly skills: (agent: Agent.Info) => Effect.Effect } @@ -52,7 +52,7 @@ export const layer = Layer.effect( const locations = yield* LocationServiceMap return Service.of({ - environment: Effect.fn("SystemPrompt.environment")(function* (model: Provider.Model) { + environment: Effect.fn("SystemPrompt.environment")(function* (model: Provider.Model, sessionCreated?: number) { const ctx = yield* InstanceState.context const references = yield* Effect.gen(function* () { yield* (yield* PluginBoot.Service).wait() @@ -67,7 +67,7 @@ export const layer = Layer.effect( ` Workspace root folder: ${ctx.worktree}`, ` Is directory a git repo: ${ctx.project.vcs === "git" ? "yes" : "no"}`, ` Platform: ${process.platform}`, - ` Today's date: ${new Date().toDateString()}`, + ` Today's date: ${new Date(sessionCreated ?? Date.now()).toDateString()}`, ``, ].join("\n"), references.length === 0