Skip to content

feat(events): add cheap preflight gates - #618

Merged
ScriptedAlchemy merged 21 commits into
mainfrom
arch/issue-595
Sep 5, 2026
Merged

feat(events): add cheap preflight gates#618
ScriptedAlchemy merged 21 commits into
mainfrom
arch/issue-595

Conversation

@ScriptedAlchemy

@ScriptedAlchemy ScriptedAlchemy commented Sep 5, 2026

Copy link
Copy Markdown
Owner

Closes #595.

Summary

Gate API

An event route uses exactly export { default as preflight } from './before.preflight.js'. The leaf receives frozen { canonical, host, signal, terminal } and returns 'execute', { outcome: 'continue' }, or { outcome: 'deny', reason }.

config.providers selects conventional provider keys for executed event routes. Omitted preserves all providers; [] mounts only framework-owned processLifetime; selected providers resolve once per request in deterministic key/source order.

Performance evidence

Seven cold starts on Node v22.23.2/Linux, medians:

Path Wall Max RSS
node -e '' 30.95 ms 42,828 KiB
generated no-op preflight 69.37 ms 51,156 KiB
full rendered route 533.12 ms 123,476 KiB

A cargo-hauler scratch migration used locally packed framework artifacts and moved shell-before/shell-after under conventional event routes. Build, typecheck, route tests, and inspect passed. Its irrelevant shell command gate measured 7 runs at a 0.06 s / 51,248 KiB median, below cargo-hauler #90's approximately 0.10 s / 64 MB routed-hook baseline. This is the consumer path described by cargo-hauler #107.

Trace surface

EventTraceEvent is a frozen discriminated union with shared execution identity, monotonic time/sequence, and bounded failure summaries. installEventTraceObserver supplies a process-local sink; observers cannot affect execution. Generated shells currently emit preflight and deferred-execute boundaries/failures; provider/render kinds are reserved for #600's unified worker trace.

Verification

  • pnpm build
  • pnpm typecheck
  • pnpm lint
  • pnpm test:unit (3,995 tests; 0 failures)
  • pnpm docs:site:build
  • preflight artifact graph/process integration (7 tests; 0 failures)
  • cargo-hauler scratch: build, typecheck, route tests, inspect

Deslop

Deslop: Cursor Grok 4.6 High Fast, 7 edits. Reused the shared record guard, removed restating comments, flattened wrapper planning/import construction, and replaced a type-bypass cast without changing behavior.

Self-review

Reviewer: Claude Fable 5.1 Thinking High (change-risk-reviewer), final diff against origin/main.

Initial findings and dispositions:

  • trace module had no production caller: wired preflight/execute boundaries and process-local observer installation
  • docs named an internal alias as public: corrected exports to agent-bundle and agent-bundle/api
  • diagnostics prose used colliding old codes: corrected to AB4840/AB4841
  • changeset omitted trace exports: added them
  • dead in-process preflight generator remained: removed it; shell/executor split is the only gated path
  • no process-level shell/executor proof and missing stdin EPIPE handler: added both
  • trace docs overstated emitted phases and zh prose had a fragment: documented emitted versus reserved phases and corrected translation

Post-deslop review: Claude Fable 5.1 Thinking High verified all 7 edits preserved behavior. It identified two low-severity items: the benchmark lacked a script entry (fixed with bench:preflight-cold-start) and the composed preflight deadline also bounded deferred standalone execution (fixed by scoping the timeout signal to the gate and preserving host-deadline render behavior). Final re-review found no actionable merge risks. After reconciling a compatible remote cleanup, a final Fable pass found an inert executor AbortController, one redundant narrowed ternary, and a stale comment; termination is now forwarded from the hook shell to the deferred executor, the residue was removed, and re-review found no remaining risk. Three GitHub review threads were fixed: deferred execution now preserves canonical observations through standalone and shared IPC, route-shaped preflight targets fail with AB4840 without suppressing either route, and terminal traces close before observer delivery. A final Fable pass found and fixed one missing IPC serialization hop; re-review found no actionable findings.

@changeset-bot

changeset-bot Bot commented Sep 5, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3311f04

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
agent-bundle Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 5, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-05T08:40:45.615709Z 749660d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

# Conflicts:
#	packages/agent-bundle/src/test/render.ts
#	packages/agent-bundle/tests/entries.test.ts

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 749660d6f4

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/agent-bundle/src/adapters/hook-contract.ts Outdated
Comment thread packages/agent-bundle/src/routes/graph.ts
Comment thread packages/agent-bundle/src/events/trace.ts Outdated
@pkg-pr-new

pkg-pr-new Bot commented Sep 5, 2026

Copy link
Copy Markdown
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle@618
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/create-agent-bundle@618
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/rsc-markdown-stream@618
npm i https://pkg.pr.new/ScriptedAlchemy/agent-bundle/@agent-bundle/runtime@618

commit: 3311f04

ScriptedAlchemy and others added 8 commits September 5, 2026 08:45
…pper-plan indirection

Deslop of the #595 branch, behavior unchanged: drop the one-line
eventRoutePreflight helper in favor of ?.preflight at its call sites,
collapse the pointless Set spread when composing project-runtime import
bindings, remove a redundant eventRoute undefined check in planHooks,
restore hookEntries in inspect-bundler to a single map expression without
the dead nested runtime-path check, and fix inconsistent indentation left
by the planHooksSurface and normalizeHooks edits.

Co-authored-by: Zack Jackson <ScriptedAlchemy@users.noreply.github.com>
# Conflicts:
#	packages/agent-bundle/src/adapters/hook-contract.ts
@ScriptedAlchemy
ScriptedAlchemy merged commit ef2abba into main Sep 5, 2026
16 checks passed
ScriptedAlchemy added a commit that referenced this pull request Sep 5, 2026
…on diagnostics to AB4843–AB4845

#618 took AB4840/AB4841 for event preflight gates and declared providers, so the
CLI surface projection codes move: AB4840→AB4843 (orphan/misplaced/duplicate
module), AB4841→AB4844 (projection contract), AB4842→AB4845 (grammar binding).
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.

Execution kernel: support cheap preflight gates/lazy providers so ubiquitous host hooks do not need a second handler model

1 participant