Skip to content

fix(daemon): count a claimed agent resume as automatic even without a history seed - #27442

Merged
OrcaWin merged 1 commit into
mainfrom
np/d1-claim-inference
Oct 11, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
np/d1-claim-inference

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​28 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​24
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​4 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2

ELI5

The terminal host decides whether a request is an "automatic restore", which gets paced, or something a person just did, which never waits. For clients that do not say which it is, the host guessed "automatic restore" only when the request carried both an agent identity and saved scrollback. A phone or another computer reconnecting to orca serve resumes its agents in brand-new terminals with no saved scrollback, so the guess never matched, and a reconnect storm went straight through. Now an agent identity alone is enough.

What Changed

  • Before: an undeclared request was charged as an automatic restore only with an agent-session claim AND a history seed. Remote --resume launches (ensureAgentSession / agent creates from paired clients) arrive on fresh terminal ids with no seed, so they were charged as interactive. They were never paced on a headless host.
  • After: an agent-session claim is enough. Plain shells, cold-restored or not, stay interactive.

Why

On headless hosts (#27428), pacing is the protection that applies to every client that has not declared an intent yet. That is all clients today. Without this change it covered only restores made on the host itself, not the reconnect storms from paired clients that #10493 describes. Callers that have not declared an intent are only ever paced, never deferred or refused (except at critical pressure after their admission window). Misclassifying a user who starts an agent therefore costs at most a short wait while a storm is running: a burst of 3 is admitted immediately, then 1 per second. The full fix is clients declaring their intent; that comes in the client PR.

Linked Issue

Refs #10493

Visual Proof

N/A: no UI. On a headless host, agent resumes from a reconnecting client now start a few at a time.

Testing

  • Automated tests added/updated
  • host-spawn-admission.test.ts: a claim without a seed is inferred as automatic. No claim is interactive.
  • terminal-spawn-gate.test.ts: a claimed create with no history seed is counted as a live automatic session.
  • pnpm tc, pnpm lint, pnpm run check:code-quality:changed and the terminal-host suites pass.

Review

Agent skill upstream boundary

  • Not applicable

Notes

  • Desktop: unaffected. It only observes.
  • Wire: no change.
  • SSH: orcad on SSH hosts paces these too.
  • Execution boundary: unchanged.

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • N/A for visuals with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote impact considered
  • pnpm lint, pnpm typecheck, and focused tests pass locally; CI covers the rest

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 7 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e8b8c47b-d29c-4c34-b3dd-c842a1bb0103

📥 Commits

Reviewing files that changed from the base of the PR and between b8f0872d699748c0146c84db56388dec2608f28d and c8d3b01.


📒 Files selected for processing (3)
  • src/main/daemon/terminal-spawn-gate.test.ts
  • src/shared/host-spawn-admission.test.ts
  • src/shared/host-spawn-admission.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 10d0789a-9d7b-4ef1-a9b1-21d0b21d758f


📥 Commits

Reviewing files that changed from the base of the PR and between f9c00ed and b8f0872d699748c0146c84db56388dec2608f28d.



📒 Files selected for processing (2)
  • src/main/daemon/terminal-spawn-gate.test.ts
  • src/shared/host-spawn-admission.ts


Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.




📝 Walkthrough
📝 Walkthrough

Walkthrough

resolveSpawnCharge now infers automatic-restore when a request has an agent-session claim and no declared intent, even if it has no history seed. Tests verify that the request receives an automatic charge and that the terminal spawn gate reports one live automatic session.



Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to b8f08

An authenticated client can submit an agent-session claim it does not own, and the host now counts an unseeded request as automatic. This can consume capacity needed by legitimate agent resumes; bind claims to their producer or explicitly accept the bounded admission risk before merging.

Pre-merge checks | Passed 3 | Failed 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check Warning The description is detailed and covers the change, reason, testing, impact, and checklist. However, the Linked Issue section contains only "Refs #10493", while the template requires an actual issue li… Replace "Refs #10493" with a direct link to issue #10493, such as "Fixes #10493" or the repository's accepted linked-issue format.
Docstring Coverage Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: treating claimed agent resumes as automatic even without a history seed.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.


Full details: Description check

Explanation

The description is detailed and covers the change, reason, testing, impact, and checklist. However, the Linked Issue section contains only "Refs #10493", while the template requires an actual issue link and states that Refs is not sufficient.




✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR



  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aed39e7f-79f1-4bdc-be32-4db736539cfc
📥 Commits

Reviewing files that changed from the base of the PR and between b53ba14 and f9c00ed.

📒 Files selected for processing (3)
  • src/main/daemon/terminal-spawn-gate.test.ts
  • src/shared/host-spawn-admission.test.ts
  • src/shared/host-spawn-admission.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

Comment on lines +104 to +108
// Why a claim alone: a remote client's `--resume` arrives on a fresh terminal id with no
// history seed, so requiring one let every reconnect storm through. An old caller is only
// ever paced, so a user-started agent costs at most a short wait during a storm.
const intent =
facts.declaredIntent ??
(facts.hasAgentSessionClaim && facts.hasHistorySeed ? 'automatic-restore' : 'interactive')
facts.declaredIntent ?? (facts.hasAgentSessionClaim ? 'automatic-restore' : 'interactive')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -eu
printf '%s\n' '--- changed diff ---'
git diff --unified=35 b53ba14fd36bc79adebc9c9058379628b5b156b5 f9c00ed9bbb81a153a151c81e592954f7559d001 -- src/shared/host-spawn-admission.ts
printf '%s\n' '--- claim admission ---'
nl -ba src/main/daemon/daemon-terminal-admission.ts | sed -n '55,105p'
printf '%s\n' '--- claim handler ---'
nl -ba src/main/daemon/terminal-host-agent-session-claim.ts | sed -n '1,80p'
printf '%s\n' '--- session create ---'
nl -ba src/main/daemon/terminal-host-session-create.ts | sed -n '95,160p'
printf '%s\n' '--- owner registry ---'
nl -ba src/shared/claimed-agent-pty-owner.ts | sed -n '100,185p'
printf '%s\n' '--- spawn accounting ---'
nl -ba src/main/daemon/terminal-spawn-gate.ts | sed -n '35,115p'

Repository: stablyai/orca

Length of output: 18191


Validate claim ownership before inferring automatic-restore.

An authenticated client can submit a structurally valid agentSessionEnsure claim without producer-ownership validation. terminal-host-session-create.ts then sets hasAgentSessionClaim even when launchAgent is absent. The changed inference classifies that non-agent PTY as automatic-restore; the claim path also creates an agent owner record, and a live PTY increments liveAutomatic.

Keep fresh-terminal, no-history resumes eligible for automatic restore, but only after the daemon validates that the claim belongs to the authenticated agent session. The observe-only gate prevents pacing or admission changes, but it does not prevent incorrect owner state or live-session accounting.

@OrcaWin
OrcaWin force-pushed the np/d1-claim-inference branch from f9c00ed to b8f0872 Compare October 11, 2026 10:21
@OrcaWin
OrcaWin force-pushed the np/d1-claim-inference branch from b8f0872 to c8d3b01 Compare October 11, 2026 10:37
@OrcaWin
OrcaWin merged commit e2339f2 into main Oct 11, 2026
38 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant