Skip to content

spike: isolate pure plugin reconciler - #7451

Closed
t3-code[bot] wants to merge 7 commits into
mainfrom
spike/plugin-runtime-pure
Closed

t3-code[bot] wants to merge 7 commits into
mainfrom
spike/plugin-runtime-pure

Conversation

@t3-code

@t3-code t3-code Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

what changed

  • isolates the framework-free reconciler from spike: compare plugin runtime models #7448 into a standalone poc
  • keeps the shared manifest and runtime contract
  • includes iterative stack-safe dependency planning and explicit finalizer ownership
  • adds a single-variant demo for activation, replacement, cleanup, and a 250-plugin chain

why

this lets reviewers evaluate the planner without effect-scope or cordis lifecycle machinery in the same diff. it is the smallest runtime model and is useful as the deterministic planner half of the recommended hybrid.

validation

  • 32 tests passed with node 24.13.1, including a 20,000-plugin dependency chain
  • package typecheck passed
  • lint with warnings denied passed
  • formatting and frozen lockfile install passed
  • demo completed successfully

limits

this is an isolated runtime poc. it does not load packages, add a sandbox, expose plugin rpc, or wire product ui.

checklist

  • this pr is focused on one implementation
  • i explained what changed and why
  • no ui changes

request provenance


Note

Medium Risk
The reconciler’s lifecycle and commit/rollback semantics are subtle and security-relevant for future plugin loading, but the change is an isolated private package with broad tests and no production wiring.

Overview
Adds a new private @t3tools/plugin-runtime-pure-poc package that extracts the framework-free plugin reconciler from the broader runtime experiment so it can be reviewed on its own.

createPureRuntime implements iterative capability-graph planning (stack-safe, cycle detection, missing-deps blocking), targeted restarts when definitions or upstream capabilities change, LIFO finalizers, staged activation with rollback on failure, frozen contribution snapshots, serialized transitions with reentrancy guards via AsyncLocalStorage, and dependent-first teardown with aggregated cleanup errors.

A shared defineRuntimeContract test suite (plus manifest tests and a 20k-plugin chain test) locks in lifecycle, rollback, observer, and edge-case behavior. PluginManifest Effect Schema validates namespaced ids, semver, capability ids, safe relative entrypoints, and declarative mobile surfaces. A demo script benchmarks a 250-plugin chain. Explicitly out of scope: package loading, sandbox, RPC, or product UI.

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

Note

Add pure plugin reconciler POC with topological activation and lifecycle management

  • Introduces a self-contained plugin runtime package (@t3tools/plugin-runtime-pure-poc) under packages/plugin-runtime-poc/ that manages plugin activation, deactivation, and reconciliation without recursion.
  • pureRuntime.ts implements createPureRuntime: plugins are ordered via iterative DFS, staged activations run in dependency order, and finalizers execute LIFO on retirement or dispose.
  • manifest.ts defines an effect/Schema-based PluginManifest that enforces namespaced IDs, strict semver, safe relative entrypoints, and disallows mobile executable entrypoints.
  • runtimeContract.ts provides a reusable test harness (defineRuntimeContract) covering activation order, reentrancy rejection, rollback, LIFO cleanup, snapshot immutability, and cycle detection.
  • A demo.ts script runs sample activations and benchmarks a 250-plugin dependency chain, printing a structured JSON report.

Macroscope summarized ae67af9.

Co-authored-by: Utkarsh Patil <73941998+UtkarshUsername@users.noreply.github.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XL 500-999 changed lines (additions + deletions). labels Aug 18, 2026
@t3-code t3-code Bot mentioned this pull request Aug 18, 2026
2 of 3 tasks
Comment thread packages/plugin-runtime-poc/src/pureRuntime.ts
Comment thread packages/plugin-runtime-poc/src/manifest.ts Outdated
@github-actions

github-actions Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 12.6 KiB 12.6 KiB −24 B (−0.2%) 15.1 KiB ✅
Codex Thread snapshot wire 6.3 KiB 6.3 KiB −8 B (−0.1%) 7.3 KiB ✅
Codex Live turn WebSocket wire 6.3 KiB 6.3 KiB −16 B (−0.2%) 7.8 KiB ✅
Codex Live turn WebSocket decoded 51.8 KiB 51.8 KiB 0 B (0.0%) 66.4 KiB ✅
Codex Live turn messages 16 16 0 (0.0%) 21 ✅
Claude Total thread wire 12.6 KiB 12.6 KiB −1 B (−0.0%) 15.1 KiB ✅
Claude Thread snapshot wire 6.3 KiB 6.3 KiB −9 B (−0.1%) 7.3 KiB ✅
Claude Live turn WebSocket wire 6.3 KiB 6.3 KiB +8 B (+0.1%) 7.8 KiB ✅
Claude Live turn WebSocket decoded 52.7 KiB 52.7 KiB 0 B (0.0%) 66.4 KiB ✅
Claude Live turn messages 16 16 0 (0.0%) 21 ✅

Baseline: bcfd485 · PR result: ae67af9 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 99.9 KiB
  • Claude decoded thread snapshot: 100.6 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

Comment thread packages/plugin-runtime-poc/src/pureRuntime.ts Outdated
@macroscopeapp

macroscopeapp Bot commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR introduces a complete new plugin runtime system (~1300 lines of new code) with complex async lifecycle management. Beyond the scope being significant new capability rather than a minor change, there is an unresolved High severity finding about a potential deadlock with function-valued thenables that warrants attention.

Not approved because:

  • 1 blocking correctness issue found at or above your repo's Minimum Blocking Severity

Adjust the Minimum Blocking Severity for this repo — including turning it Off — in Settings. You can add or adjust custom eligibility rules. Learn more.

Co-authored-by: Utkarsh Patil <73941998+UtkarshUsername@users.noreply.github.com>
@github-actions github-actions Bot added size:XXL 1,000+ changed lines (additions + deletions). and removed size:XL 500-999 changed lines (additions + deletions). labels Aug 19, 2026
@t3-code

t3-code Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

addressed the review findings in 39f328f9c:

  • definition equality is order-insensitive and includes activation callback identity
  • lifecycle events are emitted only after a composition commits
  • rollback preserves the activation error while cleanup failures go to onCleanupError
  • retirement cleanup failures are reported without rejecting an already committed snapshot
  • entrypoints reject .. escape segments, semver validation is strict, and snapshot maps are typed as sparse records

23 tests pass with node 24.13.1, including the 20,000-plugin chain, plus typecheck, lint, formatting, frozen install, and the demo.

Co-authored-by: Utkarsh Patil <73941998+UtkarshUsername@users.noreply.github.com>
@t3-code

t3-code Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

addressed the latest findings in 8c606a64c:

  • plugin activation and finalizers run in an async callback context
  • reentrant reconcile or dispose calls now fail immediately instead of deadlocking the serialized queue
  • lifecycle observer failures are isolated and reported without interrupting commit or cleanup

26 tests, including the 20,000-plugin chain, typecheck, lint with warnings denied, formatting, and frozen install pass on node 24.13.1.

Comment thread packages/plugin-runtime-poc/src/pureRuntime.ts Outdated
Comment thread packages/plugin-runtime-poc/src/pureRuntime.ts
Comment thread packages/plugin-runtime-poc/src/runtimeContract.ts
Co-authored-by: Utkarsh Patil <73941998+UtkarshUsername@users.noreply.github.com>

@cursor cursor 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c72d46c. Configure here.

Comment thread packages/plugin-runtime-poc/src/pureRuntime.ts
Co-authored-by: Utkarsh Patil <73941998+UtkarshUsername@users.noreply.github.com>
@t3-code

t3-code Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

addressed the latest review findings in 617cd2973:

  • synchronous callback microtasks can use the runtime after the callback returns
  • direct reentrant calls from active callbacks still reject immediately
  • timeout sentinels are cancelled after each test
  • the shared queued-input and late-context contract cases pass

30 tests, typecheck, lint with warnings denied, formatting, frozen install, and the demo pass on node 24.13.1.

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Aug 19, 2026
Co-authored-by: Utkarsh Patil <73941998+UtkarshUsername@users.noreply.github.com>
@macroscopeapp
macroscopeapp Bot dismissed their stale review August 19, 2026 01:19

Dismissing prior approval to re-evaluate 9b33da6

@t3-code

t3-code Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

synced the plain-function callback return regression test and fix in 9b33da605. callback lifetime tracking now treats only thenables as asynchronous.

31 tests and the full local validation pass on node 24.13.1.

const callbackState = { active: true };
try {
const result = callbackContext.run(callbackState, invoke);
if (typeof result === "object" && result !== null && "then" in result) {

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.

🟠 High src/pureRuntime.ts:188

A function-valued thenable returned by a plugin clears callbackState.active before it settles, so a reentrant runtime.reconcile() or dispose() queues behind the current transition and deadlocks when that transition awaits the thenable. The check only recognizes object results; detect function thenables as well before clearing the callback state.

Suggested change
if (typeof result === "object" && result !== null && "then" in result) {
if ((typeof result === "object" || typeof result === "function") && result !== null && "then" in result) {
🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
In file @packages/plugin-runtime-poc/src/pureRuntime.ts around line 188:

A function-valued thenable returned by a plugin clears `callbackState.active` before it settles, so a reentrant `runtime.reconcile()` or `dispose()` queues behind the current transition and deadlocks when that transition awaits the thenable. The check only recognizes `object` results; detect function thenables as well before clearing the callback state.

Co-authored-by: Utkarsh Patil <73941998+UtkarshUsername@users.noreply.github.com>
@t3-code

t3-code Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor Author

Consolidated into #8007 as one PR targeting main.

@t3-code t3-code Bot closed this Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants