Public: anyone can read this; the crew can change it.

The runtime's approval gate reads a pull's combined tip without a blocking git call #17898

opened this

Merged 20h 54m ago, live in production

The preview approval gate no longer runs git synchronously on the thread that serves requests (#17883). headUnder in src/git/combined.ts used to run up to two blocking git calls (rev-parse, then merge-base --is-ancestor) each time a cross-repo pull preview started; it now runs none.

Notes

opened this

The preview approval gate no longer runs git synchronously on the thread that serves requests (#17883). headUnder in src/git/combined.ts used to run up to two blocking git calls (rev-parse, then merge-base --is-ancestor) each time a cross-repo pull preview started; it now runs none.

How it answers now

  • The branch tip (combined/N) is read from the ref's own files on every call, using the existing readTipSync in src/git/tip.ts. A force-pushed combined branch is therefore seen right away. If the tip isn't commit, the commit answers for itself.
  • Whether the tip carries the head comes from a list of "this head is in this tip" pairs, keyed on the two commit ids and not on time. Git commits never change, so a recorded pair can't go stale. A force-push of either the head or the combined branch gives a new id, which is a new key. The list is filled by the async code that already checks this: combinedTip (reached through previewHead → pullHead before every start, wake and boot decision) and combine when it writes or keeps a tip. It holds at most 4096 pairs and is emptied when full.
  • If a pair hasn't been recorded yet, the gate stays closed: the commit answers for itself, so its own approval is asked. An async check starts so the next ask gets the right answer. A cross-repo pull still runs under its head when the commit is its combined tip, and under the commit otherwise.

What I chose not to do: make mayRun async. It sits under requestDeploy (20 callers) and its other callers in runtime.ts, runtime_events.ts and runtime_sleep.ts, so that change would spread far beyond this issue.

What to look at

  • The security edge is the "not recorded yet" case. It only ever asks for more approval, never less. It can be hit when the gate is asked about a combined tip that no async path has read since the process started, which the normal flows don't do. In that case a preview at its combined tip waits for approval until the background check finishes, and the next ask answers with the head.
  • New test in test/combined-git.test.ts: it wraps Bun.spawnSync with a counter and checks that headUnder makes 0 synchronous git calls. The old code made 2, so the test fails without this change. It also checks that an unrecorded tip answers itself, that a recorded one answers the head, and that after a force-push the old tip answers itself.
  • The existing gone-directory test in test/git-spawn-failure.test.ts still passes unchanged.

Checks run: bun x tsc --noEmit and scripts/gate.ts pass. These test files pass: combined-*, git-spawn-failure, guest-contribute, outside-lane, quarantine-doors, hollow and unused-exports. scripts/fast.ts named 3781 files, far too many to run here, so the full suite is left to the forge's check. The commit says "No door" because the gate has no page or terminal side.

🤖 Generated with Claude Code

Closes #17883

2 earlier comments
commented

The preview approval gate no longer runs git synchronously on the thread that serves requests (#17883). headUnder in src/git/combined.ts used to run up to two blocking git calls (rev-parse, then merge-base --is-ancestor) each time a cross-repo pull preview started; it now runs none.

How it answers now

  • The branch tip (combined/N) is read from the ref's own files on every call, using the existing readTipSync in src/git/tip.ts. A force-pushed combined branch is therefore seen right away. If the tip isn't commit, the commit answers for itself.
  • Whether the tip carries the head comes from a list of "this head is in this tip" pairs, keyed on the two commit ids and not on time. Git commits never change, so a recorded pair can't go stale. A force-push of either the head or the combined branch gives a new id, which is a new key. The list is filled by the async code that already checks this: combinedTip (reached through previewHead → pullHead before every start, wake and boot decision) and combine when it writes or keeps a tip. It holds at most 4096 pairs and is emptied when full.
  • If a pair hasn't been recorded yet, the gate stays closed: the commit answers for itself, so its own approval is asked. An async check starts so the next ask gets the right answer. A cross-repo pull still runs under its head when the commit is its combined tip, and under the commit otherwise.

What I chose not to do: make mayRun async. It sits under requestDeploy (20 callers) and its other callers in runtime.ts, runtime_events.ts and runtime_sleep.ts, so that change would spread far beyond this issue.

What to look at

  • The security edge is the "not recorded yet" case. It only ever asks for more approval, never less. It can be hit when the gate is asked about a combined tip that no async path has read since the process started, which the normal flows don't do. In that case a preview at its combined tip waits for approval until the background check finishes, and the next ask answers with the head.
  • New test in test/combined-git.test.ts: it wraps Bun.spawnSync with a counter and checks that headUnder makes 0 synchronous git calls. The old code made 2, so the test fails without this change. It also checks that an unrecorded tip answers itself, that a recorded one answers the head, and that after a force-push the old tip answers itself.
  • The existing gone-directory test in test/git-spawn-failure.test.ts still passes unchanged.

Checks run: bun x tsc --noEmit and scripts/gate.ts pass. These test files pass: combined-*, git-spawn-failure, guest-contribute, outside-lane, quarantine-doors, hollow and unused-exports. scripts/fast.ts named 3781 files, far too many to run here, so the full suite is left to the forge's check. The commit says "No door" because the gate has no page or terminal side.

🤖 Generated with Claude Code

commented

The preview approval gate no longer runs git synchronously on the thread that serves requests (#17883). headUnder in src/git/combined.ts used to run up to two blocking git calls (rev-parse, then merge-base --is-ancestor) each time a cross-repo pull preview started; it now runs none.

How it answers now

  • The branch tip (combined/N) is read from the ref's own files on every call, using the existing readTipSync in src/git/tip.ts. A force-pushed combined branch is therefore seen right away. If the tip isn't commit, the commit answers for itself.
  • Whether the tip carries the head comes from a small new Carried class: a list of "this head is in this tip" pairs, keyed on the two commit ids and not on time. Git commits never change, so a recorded pair can't go stale. A force-push of either the head or the combined branch gives a new id, which is a new key. It holds at most 4096 pairs and is emptied when full.
  • Where it lives: each AppsRuntime owns one Carried, not the module (the module-state rule, #12569, refuses process-wide state). pullHead fills it through previewCommit → previewHead → combinedTip; the new carried argument is optional, so other callers are unchanged. mayRun passes it to headUnder. pullHead runs before the boot and approval paths call mayRun, and it set every serving head the waking and changes-requested paths later check.
  • If a pair hasn't been recorded yet, the gate stays closed: the commit answers for itself, so its own approval is asked. An async combinedTip starts so the next ask gets the right answer. A cross-repo pull still runs under its head when the commit is its combined tip, and under the commit otherwise.

What I chose not to do: make mayRun async. It sits under requestDeploy (20 callers) and its other callers in runtime.ts, runtime_events.ts and runtime_sleep.ts, so that change would spread far beyond this issue.

What to look at

  • The security edge is the "not recorded yet" case. It only ever asks for more approval, never less. It can be hit when the gate is asked about a combined tip that no async read has seen since the process started, which the normal flows don't do. In that case a preview at its combined tip waits for approval until the background read finishes, and the next ask answers with the head.
  • New test in test/combined-git.test.ts: it wraps Bun.spawnSync with a counter and checks that headUnder makes 0 synchronous git calls. The old code made 2, so the test fails without this change. It also checks that an unrecorded tip answers itself, that a recorded one answers the head, and that after a force-push the old tip answers itself.
  • Lists updated because combined.ts no longer starts a process: its entries are gone from test/spawn-sites.test.ts and test/spawn-pipes.test.ts. These were list entries, not wrong tests.
  • Existing tests adjusted: the gone-directory test in test/git-spawn-failure.test.ts and the existing combined-tip test in test/combined-git.test.ts now pass a Carried. The combined-tip test also reads the tip through combinedTip first, so it no longer depends on what earlier tests recorded.

Checks run: bun x tsc --noEmit and scripts/gate.ts pass (0 rules failing). These test files pass: spawn-sites, spawn-pipes, module-state, combined-*, git-spawn-failure, unused-exports, outside-lane, quarantine-doors and guest-contribute. scripts/fast.ts named far too many files to run here, so the full suite is left to the forge's check. The commits say "No door" because the gate has no page or terminal side.

🤖 Generated with Claude Code

commented

The preview approval gate no longer runs git synchronously on the thread that serves requests (#17883). A fork's pull whose preview commit is its combined tip still runs under its approved head, as long as the forge has written or read that tip in this process.

How it answers now

  • The branch tip (combined/N) is read from the ref's own files on every call, using the existing readTipSync in src/git/tip.ts. A force-pushed combined branch is therefore seen right away.
  • Whether the tip carries the head comes from a Carried list of "this head is in this tip" pairs, keyed on the two commit ids and not on time. Git commits never change, so a recorded pair can't go stale. A force-push of the head or the branch gives a new id, which is a new key.
  • Each forge has one list. carriedOf(db) finds it in a WeakMap keyed by the forge's database, which is the pattern the module-state rule asks for. AppsRuntime.carried is that same instance.

Where the list is filled

  • Writing a tip: combine records every tip it writes or keeps, since every tip it returns carries the head. All four callers pass their forge's list: opening a pull and landing it (core/pulls.ts), recombining (core/recombine.ts) and following a fork (core/following.ts).
  • Reading a tip: combinedTip, reached through previewCommit from pullHead and from the preview lookup in actions/apps.ts.
  • At boot: reconcileApp already calls pullHead for each open pull before it calls mayRun on it, so the list is filled before the gate is asked. Requests that wake a preview, and the "changes requested" check, only reach commits this process has already read. Pull events call pullHead first too.

When a pair hasn't been recorded: the commit answers for itself, so its own approval is asked. One background combinedTip read starts for that pull head; Carried.readOnce makes sure repeated gate calls don't start more.

Tests

  • New: test/combined-gate.test.ts goes through AppsRuntime. It sets up a non-writer's fork pull that a writer approved.
    • A combined tip written by hand doesn't run until runtime.pullHead has read it, and runs under the head after.
    • A tip that doesn't carry the head never runs.
    • A tip written by recombine runs with no read first.
  • Spawn count: test/combined-git.test.ts checks that headUnder makes 0 synchronous git calls; the old code made 2.
  • Lists updated: combined.ts no longer starts a process, so its entries left test/spawn-sites.test.ts and test/spawn-pipes.test.ts. These were list entries, not wrong tests.
  • Existing tests adjusted: the gone-directory test in test/git-spawn-failure.test.ts and the existing combined-tip test in test/combined-git.test.ts now pass a Carried.

What I chose not to do: make mayRun async. It sits under requestDeploy (20 callers) and its other callers in runtime.ts, runtime_events.ts and runtime_sleep.ts, so that change would spread far beyond this issue.

What to look at: the edge is a combined tip nothing in this process has read or written, such as a hand-pushed combined/N before any pull event. It asks for the tip's own approval until the one background read finishes; it never grants less.

Checks run: bun x tsc --noEmit and scripts/gate.ts pass (0 rules failing). These test files pass: combined-, spawn-sites, spawn-pipes, module-state, unused-exports, git-spawn-failure, outside-lane, quarantine-doors, guest-contribute, job-slices, following- and contribute-fork-failures. The full suite is left to the forge's check. The commits say "No door" because the gate has no page or terminal side. The push hook counted the one-line change in actions/apps.ts as a route change, so an empty "Try:" commit names the two test files to run.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs