Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/opencode/src/session/prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,11 @@ const layer = Layer.effect(
let snapshotMs = 0
const session = yield* sessions.get(sessionID).pipe(Effect.orDie)

// Per turn, not per step: an instruction file edited by the turn itself applies next turn.
const instructionsStart = Date.now()
const instructions = yield* instruction.system().pipe(Effect.orDie)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: When loop() is called for an already-finished session, this fetch runs before the early-exit check and can wait 5 seconds for a configured URL. It also runs serially before history and tool preparation, whereas the previous call overlapped the first-step context effects. Move resolution after the no-op check and overlap it with first-step preparation while retaining the result for later steps.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/opencode/src/session/prompt.ts, line 1104:

<comment>When `loop()` is called for an already-finished session, this fetch runs before the early-exit check and can wait 5 seconds for a configured URL. It also runs serially before history and tool preparation, whereas the previous call overlapped the first-step context effects. Move resolution after the no-op check and overlap it with first-step preparation while retaining the result for later steps.</comment>

<file context>
@@ -1099,6 +1099,11 @@ const layer = Layer.effect(
 
+        // Per turn, not per step: an instruction file edited by the turn itself applies next turn.
+        const instructionsStart = Date.now()
+        const instructions = yield* instruction.system().pipe(Effect.orDie)
+        contextMs += Date.now() - instructionsStart
+
</file context>

contextMs += Date.now() - instructionsStart

while (true) {
yield* status.set(sessionID, { type: "busy" })
yield* Effect.logInfo("loop", { "session.id": sessionID, step })
Expand Down Expand Up @@ -1291,10 +1296,9 @@ const layer = Layer.effect(
yield* plugin.trigger("experimental.chat.messages.transform", {}, { messages: msgs })

const contextStart = Date.now()
const [skills, env, instructions, mcpInstructions, modelMsgs] = yield* Effect.all([
const [skills, env, mcpInstructions, modelMsgs] = yield* Effect.all([
sys.skills(agent),
sys.environment(model),
instruction.system().pipe(Effect.orDie),
sys.mcp(agent, session.permission),
MessageV2.toModelMessagesEffect(msgs, model),
])
Expand Down
Loading