Skip to content

feat(harness): reserve dormant Studio sessions [SAP-3292] - #998

Closed
ynadge wants to merge 1 commit into
assistant-lifecycle-transportfrom
assistant-dormant-allocation
Closed

ynadge wants to merge 1 commit into
assistant-lifecycle-transportfrom
assistant-dormant-allocation

Conversation

@ynadge

@ynadge ynadge commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Primary change type

  • Feature

Problem and motivation

Recorded Continue needs a distinct Studio session before native preparation, but normal session creation starts a Terminal and can claim automatic project setup.

Summary and scope

Add a server-only dormant allocator with an explicit not-started Terminal marker. A durable allocation ledger binds the reserved child ID to the parent and validated workspace/project/principal identity. Repeated preparation returns that exact child; collisions, changed authority, and End races fail before publication. The allocator performs no Terminal preparation, native creation, or bootstrap.

Related work

Related issue: https://linear.app/sapiom/issue/SAP-3292

Depends on #997. Native stack target: main, preserving fixed Epic 2 ancestry through #987. This is the independent allocator primitive from planned PR10; explicit activation and Continue are dependent work.

Validation

pnpm --filter @sapiom/harness exec vitest run src/core/session-manager-dormant.test.ts src/core/session-manager-close.test.ts src/core/session-manager.test.ts — 233 passed
pnpm --filter @sapiom/harness exec vitest run src/core/session-manager-dormant.test.ts src/core/session-manager-close.test.ts — root rerun, 39 passed
pnpm --filter @sapiom/harness build:server — passed
pnpm exec eslint packages/harness/src/core/session-manager.ts — passed
git diff --check — passed

Tests and documentation

Nineteen allocator cases cover no side effects, exact retry identity, restart, failed persistence, End races, authority changes, and existing ID conflicts. The internal API is documented in code. The repository has no pr:size script; measured increment is 630 changed lines, including tests.

Compatibility and release impact

  • Breaking or externally visible changes: none until the dependent Continue route calls this internal allocator; the Terminal marker is additive.
  • Changeset: N/A for this unused internal primitive; its production consumer will include release notes.
  • Fix-forward: correct allocation in a follow-up while retaining operation reservations and the original session.

Security

  • No secrets, credentials, private data, or unsanitized logs included.
  • No suspected vulnerability disclosed publicly.

AI assistance

  • AI assistance used: Codex implemented the allocator and tests; the root agent reviewed publication/authorization boundaries and reran focused verification.

Checklist

  • CONTRIBUTING.md read; maintainer-authorized issue work.
  • One focused increment, tests, relevant checks, documentation, and release impact addressed above.
  • I can explain and maintain the submitted changes.

Devin Review

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f45834cc-7f85-417b-9099-1361c0933ff1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

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.

@devin-ai-integration devin-ai-integration 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.

Devin Review found 2 potential issues.

Devin Review

Comment on lines +1561 to +1565
if (reserved === undefined && this.dormantAllocations.size >= 10_000)
throw new DormantSessionAllocationMismatchError();
this.dormantAllocations.set(id, digest);
// Keep a failed reservation: only the exact operation may retry this ID.
await this.persistDormantAllocations();

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.

🟡 Dormant allocations exhaust permanently

After 10,000 distinct reservations, allocateDormant rejects every new child ID. dormantAllocations has no reclamation path, so Recorded Continue remains unavailable.

Learn more

Every new dormant child adds one durable entry before its public session row is created. The map enforces a hard 10,000-entry limit, but no close, activation, deletion, or compaction path removes entries. Successful reservations therefore consume capacity for the lifetime of the state directory. Once full, exact retries still work, but every new child ID fails with DORMANT_SESSION_ALLOCATION_MISMATCH.

Example: A long-lived Studio profile records 10,000 distinct Continue operations over time. Operation 10,001 uses a fresh child ID and fails even though all earlier sessions are closed.

Recommended fix: Define a safe reservation lifecycle and reclaim entries after their proof is no longer required. If proofs must remain permanent, replace the fixed entry cap with bounded archival or compaction that preserves collision protection without blocking new allocations.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +1591 to +1593
await this.persistIdentityCandidate(candidate);
await authorize();
this.sessions.set(id, candidate);

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.

🔍 Allocation bypasses session broadcasts

allocateDormant publishes no status event. Its future consumer must return or refresh the row instead of relying on incremental session updates.

Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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