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

Co-authored-by: m4air <m4air@Mac.localdomain>
This commit is contained in:
OrcaWin
2026-10-11 03:55:18 -07:00
committed by GitHub
co-authored by m4air
parent 43bf799947
commit e2339f27a5
3 changed files with 32 additions and 6 deletions
@@ -105,6 +105,31 @@ describe('TerminalSpawnGate', () => {
)
})
it('counts a remote resume that arrives with a claim but no history seed', async () => {
await host.createOrAttach({
sessionId: 'remote-resume',
cols: 80,
rows: 24,
agentSessionEnsure: {
claim: {
digestVersion: 1 as const,
keyId: 'key',
identityDigest: 'r'.repeat(43),
worktreeScopeDigest: 'b'.repeat(43),
agent: 'codex' as const
},
surface: {
worktreeId: 'worktree',
tabId: 'tab-remote',
leafId: '11111111-1111-4111-8111-111111111111',
terminalHandle: 'term_remote'
}
},
streamClient: stream()
})
expect(gate.snapshot().liveAutomatic).toBe(1)
})
it('never charges an attach and frees the live slot when the session exits', async () => {
await restore('restore-a')
await host.createOrAttach({
+3 -4
View File
@@ -47,12 +47,11 @@ function mulberry32(seed: number): () => number {
}
describe('resolveSpawnCharge', () => {
it('infers automatic restore for an old caller only from a claim plus a history seed', () => {
it('infers automatic restore for an old caller from an agent claim, seeded or not', () => {
const state = createSpawnAdmissionState(LIMITS, 0)
expect(resolveSpawnCharge(state, facts(), LIMITS, 0)).toBe('automatic')
expect(resolveSpawnCharge(state, facts({ hasHistorySeed: false }), LIMITS, 0)).toBe(
'interactive'
)
// A remote client's resume: fresh terminal id, claim, no history seed.
expect(resolveSpawnCharge(state, facts({ hasHistorySeed: false }), LIMITS, 0)).toBe('automatic')
expect(resolveSpawnCharge(state, facts({ hasAgentSessionClaim: false }), LIMITS, 0)).toBe(
'interactive'
)
+4 -2
View File
@@ -133,9 +133,11 @@ export function resolveSpawnCharge(
limits: SpawnAdmissionLimits,
now: number
): SpawnCharge {
// 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')
if (intent === 'interactive') {
return 'interactive'
}