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 — refactor(core): encapsulate physical attempt execution by kitlangton · Pull Request #45294 · anomalyco/opencode

Conversation

@kitlangton

@kitlangton kitlangton commented Aug 26, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Why
The Session runner mixes logical-Step policy with provider streaming, concurrent tools, and durable settlement in a 748-line module. Reviewing a retry or compaction change requires tracing resource lifetimes and event ordering through the same loop.

What Changes
Extract one Physical Attempt into SessionStep, leaving the runner responsible for admission, context preparation, logical-Step accounting, retries, compaction, and movement. The runner now consumes explicit outcomes instead of inspecting publisher state or catching an internal retry exception.

  • runner/llm.ts shrinks from 748 to 342 lines.
  • Core production code is 132 lines smaller overall, including the new 293-line module.
  • The publisher exposes a continuation decision instead of its tool-state array and no longer duplicates the assistant ID per tool.
  • Transient drain results use Data.TaggedEnum constructors. Retry scheduling takes plain input data; the actual failure remains the existing Schema-backed AIError.

The Session execution behavioral contract is unchanged:

Situation Preserved behavior
Retryable failure before output Reuse the assistant ID and logical Step; consume the shared retry allowance.
Incomplete stream after output Settle the partial attempt and its tools, then schedule continuation with a new assistant ID.
Explicit continuation rejection Allow one immediate full-context recovery without generic backoff.
Context overflow before output Attempt runner-owned compaction before publishing the held-back provider error.
Cancellation while streaming or awaiting tools Interrupt and await owned tool fibers before durable closeout.

Attempt Lifetime
For a successful stream, the ownership boundary is:

sequenceDiagram
    participant Runner as Session runner
    participant Attempt as SessionStep
    participant Provider
    participant Tools as Local tool fibers
    Runner->>Attempt: Prepared request and recovery policy
    Attempt->>Provider: One llm.stream(request)
    loop Provider events
        Provider-->>Attempt: Event
        opt Local tool call
            Attempt->>Tools: Fork after durable Tool.Called
        end
    end
    Provider-->>Attempt: Natural EOF and completion hook
    Note over Attempt: Flush fragments and publish Step.Streamed
    Attempt->>Tools: Await every exit
    Tools-->>Attempt: All runs settled
    Note over Attempt: Capture snapshot, account usage, publish terminal event
    Attempt-->>Runner: Explicit outcome or failure
Loading

Natural EOF remains important for WebSocket checkpoint completion. Tool fibers stay in the attempt scope rather than the provider-stream scope, and Fiber.awaitAll retains every exit instead of failing fast.

Selection Fix
The Linux and Windows unit jobs exposed an existing TUI auto-copy bug. Releasing the first click cleared a start-only selection and reset OpenTUI's click counter, so subsequent clicks never selected a word or line. Auto-copy now leaves the initial cell selection alone and accepts word/line selections even when OpenTUI still marks them as starts. Click-only and empty explicit copies still clear selection, and dialog Ctrl+C still clears a selection before closing the dialog.

Demo
Real production TUI through OpenCode Drive: before 1d3c6460c1 on the left, after fde82dbf5e on the right. Both use the same 80x24 viewport, isolated fixture, simulated model response, and double/triple-click sequence. Startup and quiet reset gaps are trimmed; playback is not accelerated.

selection-before-after.mp4

Scope
The Session change is a behavior-preserving extraction, not a retry-policy redesign or a fix for existing failure-classification behavior. The separate, narrow TUI selection fix addresses the reproduced Linux and Windows unit-test failures. Public events, persistence formats, and HTTP contracts are unchanged.

Verification
Run from the indicated package directories:

# packages/core
bun typecheck
bun run build
bun run test
bun run test -- test/session-runner.test.ts test/session-runner-recorded.test.ts test/session-runner-tool-events.test.ts test/session-step.test.ts test/session-model-request.test.ts test/session-model-transport.test.ts test/session-execution.test.ts test/session-move.test.ts
bun run test -- test/session-runner.test.ts --test-name-pattern 'retry|continuation|overflow|full provider stream|interrupted' --rerun-each 3

# packages/tui
bun typecheck
bun run test
bun run test -- test/util/selection.test.ts test/util/selection-copy-on-select.test.tsx test/cli/tui/dialog-select.test.tsx --rerun-each 10
  • Full Core suite on the merged v2 head: 2,311 passed, 16 skipped, 0 failed.
  • Focused suite after cleanup: 236 passed, 0 failed.
  • Repeated retry, continuation, overflow, and interruption cases after cleanup: 105 passed, 0 failed.
  • Full TUI suite after the selection fix: 807 passed, 5 skipped, 0 failed.
  • Repeated selection and dialog tests: 250 passed, 0 failed. The two CI failures and the new initial-click regression were reproduced before the fix.
  • Typecheck and build passed; formatting, Effect simplification rules, and git diff --check passed.
  • Characterization coverage now includes natural stream exhaustion, cancellation during tool settlement and retry backoff, mixed retry/continuation identities and budget, and snapshot/nonzero-cost settlement on success and failure.
  • Scoped fibers, interruption masks, all-exit joins, and retry scheduling were checked against the installed Effect 4.0.0-rc.111 and the local v4 source. Provider tests use fixtures, not live model calls.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@kitlangton
refactor(core): encapsulate physical attempt execution
8e049bc
@github-actions github-actions Bot added the contributor label Aug 26, 2026
kitlangton added 4 commits August 26, 2026 11:13
@kitlangton
refactor(core): simplify session runner outcomes
572b66c
@kitlangton
Merge branch 'v2' into step-execution
1d3c646
@kitlangton
fix(tui): preserve multi-click selection during auto-copy
fde82db
@kitlangton
docs(core): clarify attempt settlement comments
128868c
@kitlangton
kitlangton merged commit 2602dcd into v2 Aug 26, 2026
@kitlangton
kitlangton deleted the step-execution branch August 26, 2026 16:41
@kitlangton kitlangton mentioned this pull request Aug 26, 2026
test(core): cover manual compaction cancellation #45335
Closed
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
@kitlangton
refactor(core): encapsulate physical attempt execution (anomalyco#45294)
70a9cd4
Extract physical-attempt streaming, tool execution, and durable settlement from the Session runner. Preserve logical-Step retry and recovery policy, use tagged drain outcomes, and fix multi-click selection during auto-copy.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

contributor

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@kitlangton
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — 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.