Skip to content

feat(t3layer): phase 5 ephemeral worker hierarchy overlay - #5

Merged
EtanHey merged 2 commits into
mainfrom
feat/phase5-worker-overlay
Aug 1, 2026
Merged

EtanHey merged 2 commits into
mainfrom
feat/phase5-worker-overlay

Conversation

@EtanHey

@EtanHey EtanHey commented Aug 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add a bounded process-local worker overlay keyed only by {environmentId, threadId}, with opaque roles, parent refs, creation metadata, cycle/depth/capacity enforcement, and typed overlay_unknown loss
  • extend the stock facade with overlay-aware spawn/resume, explicit canonical attach, getWorker, listChildren, and listWorkers; invalid hierarchy state is rejected before dispatch
  • keep stock T3 authoritative: provisional creates do not install metadata, restart never infers from titles, and no persistence/schema/T3 patch is introduced

Test plan

  • bun test test/overlay.test.ts test/facade.stock-http.test.ts — 45 pass, 0 fail, 150 assertions
  • bun run typecheck — exit 0
  • tracked full suite — 265 pass, 2 authorized skips, 0 fail, 897 assertions across 267 tests / 21 files
  • exact Bun 1.3.11 binary, SHA-256 1d77af7bfd811aebb7d37bec496a5eed14fe227ded3ab7866d2f39786e8107b6
  • git diff --check

Review provenance

Local CodeRabbit review was bounded to 180 seconds and timed out before findings. Red-team and blue-team fallback review found no open HIGH/MEDIUM issue; it added the mutation-proven provisional-create/read-only-resume regression before commit.

Remote CodeRabbit round 1 posted eight findings. Commit df4f312 fixes all eight; every thread was replied to and independently acknowledged as addressed. Incremental re-review completed with no new actionable comments. Codex review was requested on both heads but returned no bot response during the bounded review windows.


Note

Medium Risk
Touches the spawn/resume path and ordering (validate before dispatch), but stock-only callers are unchanged and hierarchy failures cannot mutate T3; overlay loss after restart is explicit and tested.

Overview
Adds a process-local worker overlay (createWorkerOverlay) that tracks role, parent ref, and creation metadata per {environmentId, threadId}, with reservations, depth/capacity limits, cycle and environment checks, and typed WorkerOverlayError codes.

createStockT3Facade now accepts optional overlay options and, when spawn/resume input includes both role and parentRef, validates the parent against canonical T3 via observe, reserves overlay capacity, runs the unchanged stock spawn path, and commits overlay metadata only after a reconciled spawned/partial result—provisional creates stay invisible to getWorker. New facade methods: attach, getWorker, listChildren, listWorkers. Omitting overlay fields preserves prior stock-only behavior; overlay state is not persisted and is lost on restart (explicit re-attach required).

Overlay types and constants are re-exported from the facade public surface.

Reviewed by Cursor Bugbot for commit df4f312. Bugbot is set up for automated code reviews on this repo. Configure here.

Summary by CodeRabbit

  • New Features
    • Added an optional worker overlay for tracking worker identities, parent-child relationships, and creation metadata.
    • Added worker lookup and listing capabilities.
    • Added configurable limits for worker count and hierarchy depth.
    • Added validation for invalid references, duplicate identities, cycles, roles, and parent environments.
    • Added structured errors for overlay validation, capacity, graph, and reservation failures.

Note

Add ephemeral worker hierarchy overlay to the T3 facade layer

  • Introduces a new in-memory worker hierarchy overlay (createWorkerOverlay in src/overlay.ts) that tracks parent/child relationships between workers with bounded depth and capacity, cycle detection, cross-environment rejection, and a reservation lifecycle.
  • Extends createStockT3Facade in src/facade.ts to accept an optional overlay, validate role/parentRef fields on spawn inputs, reserve overlay slots before dispatch, commit them on reconciliation, and expose new methods: attach, getWorker, listChildren, listWorkers.
  • Spawns and resumptions without overlay fields behave identically to the previous facade.
  • Adds test coverage in test/overlay.test.ts and test/facade.stock-http.test.ts for overlay validation, capacity/depth enforcement, and facade integration.
  • Risk: overlay state is process-local and not persisted; overlay records are lost on process restart, which the tests explicitly document as expected behavior.

Macroscope summarized df4f312.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@cursor

cursor Bot commented Aug 1, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_6c81dda2-5ec5-4a20-9a7e-507a70c4028f)

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds a process-local worker hierarchy overlay. The facade supports overlay-aware spawning, reconciliation, attachment, lookup, and listing while preserving direct native-runtime behavior for stock-only calls.

Changes

Worker overlay lifecycle

Layer / File(s) Summary
Overlay contracts and registry
src/overlay.ts, test/overlay.test.ts
The overlay defines worker identities, records, reservations, structured errors, depth and capacity policies, graph validation, attachment, lookup, and listing. Tests cover these behaviors.
Facade overlay lifecycle
src/facade.ts, test/facade.stock-http.test.ts
The facade accepts overlay configuration and metadata, validates references, manages reservation and reconciliation state, removes overlay metadata from native commands, and exposes worker operations. Tests cover spawn, attachment, restart, and validation behavior.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant StockT3Facade
  participant WorkerOverlay
  participant T3NativeRuntime
  Caller->>StockT3Facade: request overlay-aware spawn
  StockT3Facade->>WorkerOverlay: validate parent and reserve identity
  StockT3Facade->>T3NativeRuntime: dispatch native spawn without overlay metadata
  T3NativeRuntime-->>StockT3Facade: return SpawnResult
  StockT3Facade->>WorkerOverlay: commit worker reference
  StockT3Facade-->>Caller: return spawn result
Loading

Possibly related PRs

  • EtanHey/t3layer#2: Adds the native facade APIs extended by the overlay-aware spawn handling.
  • EtanHey/t3layer#4: Adds the stock T3 facade extended with worker-overlay lifecycle handling.

Poem

A rabbit tracks each worker’s trail,
With bounded hops and records to avail.
It reserves, commits, and checks the chain,
While native calls stay clean and plain.
“Hop safely!” says the rabbit bright.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: adding a phase 5 ephemeral worker hierarchy overlay to the T3 layer.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/phase5-worker-overlay

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.

@EtanHey

EtanHey commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@EtanHey

EtanHey commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 8

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/facade.ts`:
- Around line 156-167: Update the spawn flow at src/facade.ts lines 156-167 and
the corresponding pending flow at lines 181-192: wrap each reservation.commit
call so a WorkerOverlayError from post-write validation is rethrown with the
created ref in its details, preserving the stock result reference. In the
pending flow, verify whether reconciledRef can differ from
pending.provisionalRef; if so, reserve with null rather than the provisional ref
to avoid overlay_invalid_ref.
- Around line 61-65: Update StockFacadeSpawnInput so role and parentRef are
represented as an all-or-nothing union: one branch omits both overlay fields for
stock-only behavior, and the other requires both. Then update
requestedOverlayIdentity to use input.role without the unnecessary cast, while
preserving the existing overlay identity behavior.

In `@src/overlay.ts`:
- Around line 308-320: Replace locale-dependent sorting in listChildren and
listWorkers with a shared compareScopedKeys helper defined alongside scopedKey.
Implement the helper using deterministic relational comparison of scoped keys,
and use it in both public listing methods so their ordering is
environment-independent. Apply the changes at src/overlay.ts lines 308-320 and
321-327.
- Around line 210-222: Update materialize to accept a precomputed depth map
rather than calling depths() internally. In listWorkers and listChildren,
compute depths() once per listing operation and pass the resulting map to every
materialize call, preserving the existing unknown-record error behavior.

In `@test/facade.stock-http.test.ts`:
- Line 902: Extend the “facade worker hierarchy overlay” tests with coverage for
both missing branches: create one WorkerOverlay, pass it through
StockT3FacadeOptions.overlay to two facades, and verify the second facade can
read a record written through the shared overlay; also add an attach case whose
attached reference is absent from stock T3 and assert the
overlay_canonical_not_found error.
- Around line 1006-1008: Update the test around the result.kind assertion to
narrow the spawned result with a guard, then pass result.agentRef directly to
facade.getWorker; remove the unreachable pending.provisionalRef ternary
fallback.
- Around line 1031-1036: Extract the existing captureOverlayError helper from
test/overlay.test.ts into a shared test utility, then update the test around
restartedProcess.getWorker(ref) in test/facade.stock-http.test.ts to invoke
getWorker once through that helper and assert the captured error code. Replace
the duplicated toThrow plus bare try/catch pattern, and update
test/overlay.test.ts to import and reuse the shared helper.

In `@test/overlay.test.ts`:
- Around line 145-161: Extend the overlay tests around createWorkerOverlay and
the existing attach/commit/release flows to cover the remaining error branches:
reject roles over MAX_ROLE_BYTES and untrimmed roles, reject negative or
non-integer maxDepth with overlay_invalid_policy, return
overlay_reservation_closed for repeated commit and commit after release, and
return overlay_invalid_ref when committing a ref different from the reserved
ref. Assert each error code explicitly while preserving the existing
duplicate-ref and invalid-role coverage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 025aa893-8b53-4898-9012-24a9896a798d

📥 Commits

Reviewing files that changed from the base of the PR and between 0b6cd4c and ab5a953.

📒 Files selected for processing (4)
  • src/facade.ts
  • src/overlay.ts
  • test/facade.stock-http.test.ts
  • test/overlay.test.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Macroscope - Correctness Check
🔇 Additional comments (29)
src/overlay.ts (8)

1-60: LGTM!


75-96: LGTM!


98-120: LGTM!


137-150: LGTM!


152-184: LGTM!


186-208: LGTM!


224-287: LGTM!


289-307: LGTM!

test/overlay.test.ts (6)

9-17: LGTM!


20-43: LGTM!


45-66: LGTM!


68-96: LGTM!


98-114: LGTM!


116-143: LGTM!

src/facade.ts (9)

5-17: LGTM!

Also applies to: 46-59


67-69: LGTM!


71-95: LGTM!


97-120: LGTM!


131-136: LGTM!


148-155: LGTM!

Also applies to: 170-180


195-218: LGTM!


138-146: 🗄️ Data Integrity & Integration

No change needed.

runtime.observe(ref, operation) already rejects mismatched ref.environmentId with environment_changed before returning a thread snapshot, so requireCanonical only needs the thread-id comparison after this call.


122-124: 🩺 Stability & Availability

No change needed. partial results use the native ref after create receipt projection, while conflicts return a create_protocol_failure with a provisionalRef.

test/facade.stock-http.test.ts (6)

18-18: LGTM!

Also applies to: 83-89


902-957: LGTM!


959-1005: LGTM!

Also applies to: 1009-1013


1015-1030: LGTM!

Also applies to: 1037-1038


1040-1066: LGTM!


1068-1103: LGTM!

Comment thread src/facade.ts Outdated
Comment thread src/facade.ts
Comment thread src/overlay.ts Outdated
Comment thread src/overlay.ts
Comment thread test/facade.stock-http.test.ts
Comment thread test/facade.stock-http.test.ts Outdated
Comment thread test/facade.stock-http.test.ts Outdated
Comment thread test/overlay.test.ts
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@cursor

cursor Bot commented Aug 1, 2026

Copy link
Copy Markdown

Bugbot couldn't run - usage limit reached

Bugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit.

A user or team admin can review and increase usage limits in the Cursor dashboard.

(requestId: serverGenReqId_58a337a5-1a6a-4998-91e3-64dffb0d0404)

@EtanHey

EtanHey commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@EtanHey

EtanHey commented Aug 1, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@coderabbitai

coderabbitai Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@EtanHey
EtanHey merged commit 5801c68 into main Aug 1, 2026
3 checks passed
@EtanHey
EtanHey deleted the feat/phase5-worker-overlay branch August 1, 2026 20:05
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