GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(core): reset steps for promoted prompts (#33452) · koji/opencode@dc468bd

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • AGENTS.md
  • CONTEXT.md
  • packages
    • core
      • src/session/runner
        • llm.ts
      • test
        • session-runner.test.ts
    • sdk
      • js/src/v2/gen
        • sdk.gen.ts
      • openapi.json
    • server/src/groups
      • session.ts
  • specs/v2
    • schema-changelog.md
    • session.md
    • todo.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎AGENTS.md‎

Copy file name to clipboardExpand all lines: AGENTS.md
+2-2Lines changed: 2 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const table = sqliteTable("session", {
152152
- Keep `SessionExecution` process-global and Session-ID based. Its local implementation owns the process-local Session coordinator and discovers placement through `SessionStore` plus `LocationServiceMap.get(session.location)` only when a drain starts; no layer should take a Session ID. V2 interruption targets the active process-local ownership chain for that Session; idle or missing interruption is a no-op.
153153
- Keep `SessionRunner`, model resolution, tool registry, permissions, and filesystem Location-scoped. Omitted `Location.workspaceID` means implicit-local placement; explicit workspace identity remains reserved for future placement semantics.
154154
- Preserve one explicit `llm.stream(request)` call per provider turn and reload projected history before durable continuation. Do not bridge through legacy `SessionPrompt.loop(...)` or delegate orchestration to an in-memory tool loop.
155-
- Keep local Session drains process-local until clustering is implemented. `SessionRunCoordinator` joins explicit same-Session resumes, coalesces prompt wakeups, and allows different Sessions to run concurrently. Advisory wakes drain eligible durable inbox rows only; post-crash activity recovery requires a separate explicit design before it may retry provider work.
156-
- Keep delivery vocabulary explicit. Prompts steer by default and coalesce into the active activity at the next safe provider-turn boundary. Explicit `queue` inputs open FIFO future activities one at a time after the active activity settles.
155+
- Keep local Session drains process-local until clustering is implemented. `SessionRunCoordinator` joins explicit same-Session resumes, coalesces prompt wakeups, and allows different Sessions to run concurrently. Advisory wakes drain eligible durable inbox rows only; post-crash continuation recovery requires a separate explicit design before it may retry provider work. A drain has no durable identity or transcript boundary.
156+
- Keep delivery vocabulary explicit. Prompts steer by default and promote at the next safe provider-turn boundary while the current drain requires continuation. An explicit `queue` input remains pending until the Session would otherwise become idle; promote one queued input at that boundary, then reevaluate continuation before promoting another. Promoting any new user input resets the selected agent's provider-turn allowance; a batch of steers resets it once.
157157
- Keep EventV2 replay owner claims separate from clustered Session execution ownership.
158158
- Keep the System Context algebra, registry, and built-ins in `src/system-context`; keep Context Source producers with their observed domains, and keep Session History selection plus Context Epoch persistence Session-owned.
Collapse file

‎CONTEXT.md‎

Copy file name to clipboardExpand all lines: CONTEXT.md
+17Lines changed: 17 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ An expected temporary inability to observe a **Context Source** value; the runti
3939
**Safe Provider-Turn Boundary**:
4040
The point immediately before a provider call, after durable input promotion and any required tool settlement, where context changes may be admitted chronologically.
4141

42+
**Admitted Prompt**:
43+
A durable user input accepted into the Session inbox but not yet included in **Session History**.
44+
45+
**Prompt Promotion**:
46+
The durable transition that removes an **Admitted Prompt** from pending input and appends its user message to **Session History**.
47+
48+
**Provider Turn**:
49+
One request to a model provider and the response projected from that request.
50+
51+
**Session Drain**:
52+
One process-local execution span that promotes eligible input and runs required **Provider Turns** until no immediate continuation remains. A Session Drain has no durable identity or transcript boundary.
53+
4254
**Model Tool Output**:
4355
The bounded projection of a Core-executed tool result persisted in Session history and replayed to the model. A tool may shape this projection semantically, but the Tool Registry enforces the final size limit.
4456

@@ -67,6 +79,11 @@ The host-supplied environment overlay applied by the server when creating a PTY,
6779
- Changes from multiple **Context Sources** admitted at one safe boundary combine into one **Mid-Conversation System Message**.
6880
- Context changes are sampled and admitted lazily at a **Safe Provider-Turn Boundary**, never pushed asynchronously when their source changes.
6981
- At a **Safe Provider-Turn Boundary**, newly promoted user input or settled tool results precede any combined **Mid-Conversation System Message**.
82+
- An **Admitted Prompt** is replayable pending input, not yet model-visible **Session History**.
83+
- **Prompt Promotion** atomically consumes the pending inbox entry and appends its model-visible user message.
84+
- Steering prompts promote at the next **Safe Provider-Turn Boundary** while the current **Session Drain** still requires continuation. Promoting any newly admitted user input resets the selected agent's provider-turn allowance; multiple prompts promoted at one boundary reset it once.
85+
- A queued prompt does not promote while the current **Session Drain** requires continuation. The runner promotes one queued prompt when the Session would otherwise become idle, then reevaluates continuation before promoting another.
86+
- A **Session Drain** is process-local coordination rather than a durable domain entity. Durable recovery must reason from prompts, projected history, provider attempts, and tool state rather than inventing an enclosing execution identity.
7087
- The first provider turn renders the latest complete **Baseline System Context** and initializes its **Context Snapshot** without emitting a redundant **Mid-Conversation System Message**; unavailable initial context blocks the turn instead of persisting an incomplete baseline.
7188
- Initial **System Context** preparation precedes the first durable input promotion so an unavailable baseline leaves that input pending and retryable; ordinary reconciliation remains after promotion.
7289
- Compaction starts a new **Context Epoch** with a freshly rendered **Baseline System Context** and **Context Snapshot**; prior **Mid-Conversation System Messages** remain durable audit history but leave projected model history.
Collapse file

‎packages/core/src/session/runner/llm.ts‎

Copy file name to clipboardExpand all lines: packages/core/src/session/runner/llm.ts
+29-24Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import { MAX_STEPS_PROMPT } from "./max-steps"
7979
* - [ ] Update title, summaries, compaction state, and cleanup in bounded background work.
8080
*
8181
* Use `llm.stream(request)` for each provider turn. Keep tool execution and continuation here.
82-
* Durable activity recovery remains a separate future slice with an explicit retry policy.
82+
* Durable continuation recovery remains a separate future slice with an explicit retry policy.
8383
*
8484
* The current slice loads V2 history, translates it, resolves a model through a core service, and persists one
8585
* provider turn. Registry definitions are advertised, local tool calls are settled durably, and an
@@ -142,20 +142,19 @@ export const layer = Layer.effect(
142142

143143
type TurnTransition =
144144
// Automatic compaction completed; rebuild the request from compacted history.
145-
| { readonly _tag: "ContinueAfterCompaction" }
145+
| { readonly _tag: "ContinueAfterCompaction"; readonly step: number }
146146
// Overflow compaction completed; rebuild once through the path without overflow recovery.
147-
| { readonly _tag: "ContinueAfterOverflowCompaction" }
147+
| { readonly _tag: "ContinueAfterOverflowCompaction"; readonly step: number }
148148

149149
class TurnTransitionError extends Error {
150150
constructor(readonly transition: TurnTransition) {
151151
super()
152152
}
153153
}
154154

155-
const continueAfterCompaction = new TurnTransitionError({ _tag: "ContinueAfterCompaction" })
156-
const continueAfterOverflowCompaction = new TurnTransitionError({
157-
_tag: "ContinueAfterOverflowCompaction",
158-
})
155+
const continueAfterCompaction = (step: number) => new TurnTransitionError({ _tag: "ContinueAfterCompaction", step })
156+
const continueAfterOverflowCompaction = (step: number) =>
157+
new TurnTransitionError({ _tag: "ContinueAfterOverflowCompaction", step })
159158

160159
const loadSystemContext = (agent: AgentV2.Selection) =>
161160
Effect.all([systemContext.load(), skillGuidance.load(agent), referenceGuidance.load()], {
@@ -175,20 +174,23 @@ export const layer = Layer.effect(
175174
const initialized = yield* SessionContextEpoch.initialize(db, loadSystemContext(agent), session.id)
176175
const toolFibers = yield* FiberSet.make<void, ToolOutputStore.Error>()
177176
let needsContinuation = false
177+
let currentStep = step
178178
if (promotion) {
179179
const cutoff = yield* EventV2.latestSequence(db, session.id)
180-
if (promotion === "steer") yield* SessionInput.promoteSteers(db, events, session.id, cutoff)
180+
let promoted = 0
181+
if (promotion === "steer") promoted = yield* SessionInput.promoteSteers(db, events, session.id, cutoff)
181182
if (promotion === "queue") {
182-
yield* SessionInput.promoteNextQueued(db, events, session.id)
183-
yield* SessionInput.promoteSteers(db, events, session.id, cutoff)
183+
promoted += Number(yield* SessionInput.promoteNextQueued(db, events, session.id))
184+
promoted += yield* SessionInput.promoteSteers(db, events, session.id, cutoff)
184185
}
186+
if (promoted > 0) currentStep = 1
185187
}
186188
const system =
187189
initialized ?? (yield* SessionContextEpoch.prepare(db, events, loadSystemContext(agent), session.id))
188190
const model = yield* models.resolve(session)
189191
const entries = yield* SessionHistory.entriesForRunner(db, session.id, system.baselineSeq)
190192
const context = entries.map((entry) => entry.message)
191-
const isLastStep = agent.info?.steps !== undefined && step >= agent.info.steps
193+
const isLastStep = agent.info?.steps !== undefined && currentStep >= agent.info.steps
192194
const toolMaterialization = isLastStep ? undefined : yield* tools.materialize(agent.info?.permissions)
193195
const promptCacheKey = /^ses_[0-9a-f]{64}$/.test(session.id) ? session.id.slice(4) : session.id
194196
const request = LLM.request({
@@ -202,7 +204,7 @@ export const layer = Layer.effect(
202204
toolChoice: isLastStep ? "none" : undefined,
203205
})
204206
if (yield* compaction.compactIfNeeded({ sessionID: session.id, entries, model, request }))
205-
return yield* Effect.die(continueAfterCompaction)
207+
return yield* Effect.die(continueAfterCompaction(currentStep))
206208
const publisher = createLLMEventPublisher(events, {
207209
sessionID: session.id,
208210
agent: agent.id,
@@ -272,7 +274,7 @@ export const layer = Layer.effect(
272274
isContextOverflowFailure(overflowFailure ?? failure) &&
273275
(yield* restore(recoverOverflow({ sessionID: session.id, entries, model, request })))
274276
)
275-
return yield* Effect.die(continueAfterOverflowCompaction)
277+
return yield* Effect.die(continueAfterOverflowCompaction(currentStep))
276278
if (overflowFailure) yield* publish(overflowFailure)
277279
const llmFailure = failure instanceof LLMError ? failure : undefined
278280
if (llmFailure && !publisher.hasProviderError()) {
@@ -306,15 +308,15 @@ export const layer = Layer.effect(
306308
yield* withPublication(publisher.failUnsettledTools("Provider did not return a tool result", true))
307309
if (stream._tag === "Failure") return yield* Effect.failCause(stream.cause)
308310
if (settled._tag === "Failure") return yield* Effect.failCause(settled.cause)
309-
return !publisher.hasProviderError() && needsContinuation
311+
return { needsContinuation: !publisher.hasProviderError() && needsContinuation, step: currentStep }
310312
}),
311313
)
312314
}, Effect.scoped)
313315
type RunTurn = (
314316
sessionID: SessionSchema.ID,
315317
promotion: SessionInput.Delivery | undefined,
316318
step: number,
317-
) => Effect.Effect<boolean, RunError>
319+
) => Effect.Effect<{ readonly needsContinuation: boolean; readonly step: number }, RunError>
318320

319321
const runAfterOverflowCompaction: RunTurn = Effect.fnUntraced(function* (sessionID, promotion, step) {
320322
return yield* runTurnAttempt(sessionID, promotion, step).pipe(
@@ -324,7 +326,7 @@ export const layer = Layer.effect(
324326
if (defect.transition._tag === "ContinueAfterOverflowCompaction")
325327
return yield* Effect.die("Post-compaction provider attempt cannot recover another overflow")
326328
yield* Effect.yieldNow
327-
return yield* runAfterOverflowCompaction(sessionID, undefined, step)
329+
return yield* runAfterOverflowCompaction(sessionID, undefined, defect.transition.step)
328330
}),
329331
),
330332
)
@@ -337,8 +339,8 @@ export const layer = Layer.effect(
337339
if (!(defect instanceof TurnTransitionError)) return yield* Effect.die(defect)
338340
yield* Effect.yieldNow
339341
if (defect.transition._tag === "ContinueAfterOverflowCompaction")
340-
return yield* runAfterOverflowCompaction(sessionID, undefined, step)
341-
return yield* runTurn(sessionID, undefined, step)
342+
return yield* runAfterOverflowCompaction(sessionID, undefined, defect.transition.step)
343+
return yield* runTurn(sessionID, undefined, defect.transition.step)
342344
}),
343345
),
344346
)
@@ -353,16 +355,19 @@ export const layer = Layer.effect(
353355
if (!input.force && !hasSteer && !hasQueue) return
354356
yield* failInterruptedTools(input.sessionID)
355357
let promotion: SessionInput.Delivery | undefined = hasSteer ? "steer" : hasQueue ? "queue" : undefined
356-
let openActivity = input.force || hasSteer || hasQueue
357-
while (openActivity) {
358+
let shouldRun = input.force || hasSteer || hasQueue
359+
while (shouldRun) {
358360
let needsContinuation = true
359-
for (let step = 1; needsContinuation; step++) {
360-
needsContinuation = yield* runTurn(input.sessionID, promotion, step)
361+
let step = 1
362+
while (needsContinuation) {
363+
const result = yield* runTurn(input.sessionID, promotion, step)
364+
needsContinuation = result.needsContinuation
365+
step = result.step + 1
361366
promotion = "steer"
362367
if (!needsContinuation) needsContinuation = yield* SessionInput.hasPending(db, input.sessionID, "steer")
363368
}
364-
openActivity = yield* SessionInput.hasPending(db, input.sessionID, "queue")
365-
promotion = openActivity ? "queue" : undefined
369+
shouldRun = yield* SessionInput.hasPending(db, input.sessionID, "queue")
370+
promotion = shouldRun ? "queue" : undefined
366371
}
367372
})
368373

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.