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): skip execution claims held by another live process during restart recovery by alohaninja · Pull Request #51215 · anomalyco/opencode

Conversation

@alohaninja

@alohaninja alohaninja commented Sep 24, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown

Issue for this PR

Closes #51213

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Startup recovery treats every execution claim as orphaned. That holds for a successor managed server, but not when an unregistered opencode serve (for example, one bundled by a desktop client) shares the database. The service then resumes that server's live sessions, and both servers run the same session.

This PR records the owning process on claims (a new nullable session_v2.claim_pid column) and on recoverable background job records (an optional pid in the KV payload). The sweep skips claims and jobs whose process is still alive and isn't the current one. Claims with no pid, a dead pid, or this process's pid behave as before, so crash and restart recovery don't change. Re-claiming keeps the original claim time but moves the pid to the resuming process, so a later sweep won't treat a resumed session as orphaned.

The liveness check is process.kill(pid, 0). If that API isn't available, the claim is treated as dead, which is today's behavior.

Subagent recovery is skipped when either the parent or the child is held by a live process, since that owner delivers the result. Claim owners are read again right before the final resume loop, so a session claimed while jobs recover isn't taken over.

Known limits: the liveness check only sees processes on the same host, so servers in separate containers or hosts sharing one database aren't protected (and two containers where both servers are PID 1 look like the same owner). Pids ≤ 1 are treated as unknown and resumed as before. A reused PID can make a dead owner look alive, which leaves the session suspended until a later boot rather than taking it over. Background shells in an idle session aren't claim-backed, so they're covered only through their job record.

How did you verify your code works?

  • 11 new tests in packages/core/test/session-execution.test.ts, covering claim stamping, live owner skipped, dead owner resumed, re-stamp on resume, job pid persisted, live-owner job left pending, a live-owned child claim kept, pid 1 treated as unknown, a mixed local/foreign sweep, and subagent jobs skipped when the child or parent is live-owned. They spawn real live and exited processes via process.execPath, not mocks. All 46 tests in that file pass. Deleting each guard (child-claim retention, the subagent skip, the pid validation) fails its test.
  • bun typecheck in packages/core and packages/server, bun run migration --check, and oxlint and prettier on the changed files.
  • Ran 14 related core test files against both this branch and origin/v2, one file at a time. Results match everywhere; two tests fail identically on both (mcp "exposes every connection operation", one in session-checkpoint-transport).
  • End-to-end with isolated XDG dirs: server A running two subagents, then server B started with --service. Before this change, A's next step failed with Anthropic Messages system updates cannot split a local tool call from its tool result. With it, B leaves the session alone and A finishes normally. As a control, killing A with -9 and restarting B still resumes the session.

Screenshots / recordings

Not a UI change.

pr51215-claim-owner-pid

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Sorry, something went wrong.

Uh oh!

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

All reactions
@github-actions github-actions Bot added the needs:issue label Sep 24, 2026
@github-actions

github-actions Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions

github-actions Bot commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

All reactions

Sorry, something went wrong.

Uh oh!

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

@alohaninja
alohaninja force-pushed the session-claim-owner branch from 64c8a80 to 8df933c Compare September 24, 2026 20:48
This was referenced Sep 28, 2026
Anthropic system updates reject otherwise recoverable tool history #51764
Closed
Background service resumes sessions still running on another server that shares the database #51213
Open
fix(ai): defer system updates until local tool results #51765
Closed
Session recovery loses client environment and inherits another agent identity #51784
Open
fix(core): wait for client environment before recovering sessions #51786
Closed
@gszep

gszep commented Sep 29, 2026

Copy link
Copy Markdown

This PR already references #51213 (Closes #51213) in the description. This PR targets v2, while the repository default is dev, so GitHub's closingIssuesReferences check currently returns empty here — same needs:issue false positive already flagged on #51757/#51765/#51786. Could a maintainer add the Development link to #51213, or bring the body-reference fallback to dev?

All reactions

Sorry, something went wrong.

Uh oh!

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

alohaninja and others added 2 commits October 2, 2026 16:31
@alohaninja @claude
fix(core): skip execution claims held by another live process during …
8710165
…restart recovery

Claims and recoverable background jobs record the owning process. The startup sweep no longer resumes sessions that an unregistered server sharing the database is still running.

Co-Authored-By: Claude <[email protected]>
@alohaninja @claude
fix(core): close subagent and stale-snapshot gaps in claim ownership …
12e7d27
…recovery

Skip subagent recovery when the parent or child claim is held by a live process, re-read claim owners before the final resume loop, ignore pids that cannot identify a single other process (<= 1), use Schema.Int for job pids, and make the test process helpers portable to Windows.

Co-Authored-By: Claude <[email protected]>
@alohaninja
alohaninja force-pushed the session-claim-owner branch from 8df933c to 12e7d27 Compare October 2, 2026 20:34
@Starefossen Starefossen mentioned this pull request Oct 8, 2026
OpenCode v2: upstream issues and cplt mitigations navikt/cplt#733
Closed
@thdxr
thdxr changed the base branch from v2 to dev October 10, 2026 19:17
@github-actions github-actions Bot removed the needs:issue label Oct 10, 2026
@alohaninja @codex
chore(core): sync claim recovery fix with current V2 dev
4e6a4c3
Merge current upstream dev into session-claim-owner, preserving the live
process recovery guard and both newer upstream database migrations.

Resolve the schema snapshot, migration registry and AGENTS conflicts
without changing the recovery fix's scope.

Verified with Bun 1.4.2: migration check, 72 focused tests, 6616 core
tests passing (43 skipped), and repository-wide lint/typecheck.
Disabling the live-owner guard makes its regression test fail.

Co-Authored-By: GPT-6 Astra <[email protected]>
@user753 user753 mentioned this pull request Oct 13, 2026
Background service resumes opencode run --standalone sessions after the run was killed, without its permissions or step limit (runaway: 1,660 steps, ~$24) #55076
Open
@m2dumpling m2dumpling mentioned this pull request Oct 13, 2026
fix(core): exclude standalone executions from restart recovery #55174
Closed
3 of 6 tasks
@alohaninja

alohaninja commented Oct 14, 2026

Copy link
Copy Markdown
Author

This is now synced to current V2 dev; the PR remains 11 files with the original recovery fix. #51213 has additional reproductions on 2.0.22 and 2.0.24. Could a maintainer approve the pending test, check, and nix-eval workflows?

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions

github-actions Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot closed this Oct 24, 2026
@github-actions github-actions Bot added the automated-pr-cleanup label Oct 24, 2026
@rebelliard rebelliard mentioned this pull request Oct 25, 2026
fix(core): skip execution claims held by another live process on restart #58929
Closed
3 of 6 tasks
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

automated-pr-cleanup

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Background service resumes sessions still running on another server that shares the database

Uh oh!

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

2 participants

@alohaninja @gszep
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 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.