Skip to content

fix(core): interrupt sessions before inactivity eviction - #47629

Merged
kitlangton merged 2 commits into
v2from
eviction-interrupt
Sep 6, 2026
Merged

kitlangton merged 2 commits into
v2from
eviction-interrupt

Conversation

@kitlangton

@kitlangton kitlangton commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

Why

A session waiting for a question can outlive the location's 60-minute inactivity deadline. Eviction removes the service graph from the cache while its execution still holds the old graph. Answering the question then reaches a replacement Form.Service: the question disappears, but the original tool keeps waiting and the session never settles.

What Changes

Before: inactivity eviction detaches a running execution from the services used by subsequent client requests.

After: inactivity eviction interrupts every active session at that location, waits for tool cleanup and terminal execution settlement, then invalidates the cached graph. The question is cancelled and the TUI shows interrupted.

The execution records reason: "inactivity" and releases its recovery claim, so a server restart does not resume deliberately expired work. The wait covers the selected execution's settlement, not fresh work admitted during its cleanup. If new work starts in the same or another session, the sweep defers eviction and future sweeps continue. Location comparisons use the cache's canonical path representation, including on Windows.

sequenceDiagram
    participant Activity as LocationActivity
    participant Execution as SessionExecution
    participant Tool as Running tools
    participant Cache as LocationServiceMap
    Activity->>Execution: interrupt(location's sessions, inactivity, awaitSettlement)
    Execution->>Tool: interrupt
    Tool-->>Execution: cleanup complete
    Execution->>Execution: publish terminal, release recovery claim
    Execution-->>Activity: selected executions settled
    Activity->>Execution: check for new active sessions
    Activity->>Cache: invalidate if location has no active sessions
Loading

Demo

eviction-final-comparison.mp4

Matched OpenCode Drive 2.1.0 recording: before b2cecc6350, after 34f77d5877. Both run the real TUI and question tool with an identical simulated model response, 95×30 viewport, and Enter press after expiry. Both temporarily accelerate the existing 60-minute TTL to 5 seconds and the 1-minute sweep to 1 second. Production timings are unchanged. The 10-second comparison shows the initial question, automatic interruption on the right, and the orphaned spinner on the left after Enter.

Scope

Owns inactivity-eviction ordering through the existing process-local execution coordinator, plus the durable interruption reason and regenerated client types. Supersedes the active-location retention policy proposed in #47626.

Verification

# packages/core
bun run test test/location-activity.test.ts test/location-layer.test.ts test/session-execution.test.ts test/session-run-coordinator.test.ts test/form.test.ts test/permission.test.ts
bun run test test/location-activity.test.ts
bun typecheck

# packages/server
bun typecheck

# packages/client
bun run generate

# repo root
bunx oxlint packages/core/src/location-activity.ts packages/core/src/session/execution.ts packages/core/src/session/run-coordinator.ts packages/core/test/location-activity.test.ts
opencode-drive check .drive-output/eviction-demo.ts
  • All 204 focused tests passed. The original three eviction regressions fail on the base revision. A fourth regression fails with the chain-wide awaitIdle implementation and passes with the selected-execution settlement wait.
  • Regressions use real execution ownership, forms, cache eviction, and recovery claims. They cover one or two active sessions, delayed cleanup, an independently idle workspace at the same directory, and same-session or different-session work admitted during cleanup. The same-session case also proves a later-expiring graph is still evicted while the successor execution is active.
  • Core and Server typechecks passed; the required pre-push typecheck completed all 33 package tasks successfully. Lint reports no warnings or errors.
  • Drive asserts that the base tool remains running, the fixed tool settles, the fixed session outcome is interrupted, and no pending question remains.

@kitlangton
kitlangton merged commit 2a895b9 into v2 Sep 6, 2026
12 checks passed
@kitlangton
kitlangton deleted the eviction-interrupt branch September 6, 2026 15:11
jinhuang712 pushed a commit to jinhuang712/opencode that referenced this pull request Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant