Skip to content

docs(quest): plan gate admission with headroom - #180

Merged
kixelated merged 10 commits into
mainfrom
quest/plan-gate-headroom
Oct 21, 2026
Merged

kixelated merged 10 commits into
mainfrom
quest/plan-gate-headroom

Conversation

@kixelated

@kixelated kixelated commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Plans the follow-ups from the quest gate contention measurements in #177, plus small leftovers from #128 and #178.

Changes

  • New: quest/m0/gate-headroom.md [M], ranked first in m0 where the gate quest was. It covers:
    • admitting at once while the host has room, counting each recent admission against both load and free memory;
    • spacing queued admissions SETTLE_MS apart instead of about two windows;
    • a stable claim directory;
    • backward clock steps;
    • forwarding Ctrl-C once in both quest gate and quest worktree run (landed in kixelated/quest#178).
  • Updated quest/m0/worktree.md: its out-of-scope Ctrl-C bullet links to the new quest instead of this PR.
  • Folded into quest/m0/kix/inbox-accuracy.md: slim test/seed.test.ts rather than raising its timeout as the seed grows (cloudflare/test/seed.test.ts). It was the only test to time out at 8× overload.
  • Not planned here:

Decision paper trail

Gate behaviour after the #177 measurements (on a 24-core host, a burst of 8 took 104 s gated versus 19 s ungated; the gate only prevented timeouts at about 8 suites per CPU):

  • ✅ Admit with headroom: admit at once while load plus recent admissions stays under the CPU count, keeping spacing only near the limit. This reverses the 2026-10-15 "no adaptive scheduler" decision; memory admission stays.
  • Fix the spacing only
  • Stop gating by default
  • Accept as is

Review round 1 (review): all 11 findings (12 threads, the P1 posted twice) fixed in 5dfc30e, including counting recent admissions against free memory (P1), which keeps "memory admission stays". The fixes made the quest [M].

Codex review rounds 2 and 3 (on 5dfc30e and 83b2c83): fixed in 83b2c83 and 3f6adc2. The count now comes from unexpired records. A future-dated record has its time rewritten to now instead of being dropped. Prune, count, and record run under a host-wide lock, so a burst elects a winner instead of livelocking.

Design checkpoint after Codex round 4 (on 3201727), decided by the orchestrator under the maintainer's standing instruction:

  • ✅ State the admission mechanism as requirements, and list every review finding from rounds 1–4 as a hazard the implementation must test, including round 4's PID reuse on macOS/Windows and forward clock steps. Done in d8b6cc6. The recorded decisions and the three-band rule are unchanged.
  • Keep fixing the mechanism one finding at a time
  • Merge as is
  • Drop the PR

After the checkpoint, Codex found two more issues, both fixed. The claim directory is now a requirement for one location that never switches with environment or login sessions, with /run/user/<uid> coming and going listed as a hazard (0d96219). The Ctrl-C fix now skips forwarding only SIGINT in the foreground group and always forwards SIGHUP and SIGTERM (d3983e2). Codex found no issues on d3983e2, and the landed-quest guard passes against main.

Reviewer while Codex is out of credits:

  • ✅ An independent Claude review: a fresh sub-agent runs /code-review --comment.
  • Add Codex credits
  • Hold until the limit resets

just check and just test pass.

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

Follow-up of the contention measurements in #177: admit at once while the
host has room, fix the two-window spacing, a stable claim directory,
backward clock steps, and forwarding Ctrl-C once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-10-21T23:31:57.217862Z d3983e2 Manual request
🔒 Security Review ✅ Completed 2026-10-21T23:32:16.037763Z d3983e2 Manual request
ℹ️ 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.

@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: ecd0bf28c0

ℹ️ 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 quest/m0/gate-headroom.md Resolved

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Independent review standing in for Codex, at ecd0bf2. Docs-only, so I checked the plan against src/cli/gate.ts, the README's "Gate expensive commands" section, scripts/gate-bench.sh, the measurements and follow-ups in kixelated/quest#177, the decisions in kixelated/quest#128, and kixelated/quest#178 (quest worktree run). I didn't re-open the recorded choices: headroom admission, the reversal of "no adaptive scheduler", and keeping memory admission.

quest check passes (48 documents). These factual claims hold: about 10 s effective spacing, the split claim directory, the backward clock step allowing one extra adjacent admission, the doubled Ctrl-C, the gate-bench.sh overhead dependence on XDG_RUNTIME_DIR, and 104 s versus 19 s with timeouts only at 8x.

Findings:

  • P1: as written, headroom admission bypasses memory admission for a burst, because the memory check counts no recent admissions.
  • P2: admission records need to last a minute and be counted atomically, and the current one-claim-per-window design does neither.
  • P2: "near the limit" is undefined.
  • P2: quest worktree run exists only in #178, which is still open.
  • P3: the spacing fix, claim directory rule, monotonic clock, Ctrl-C example, 8x bench expectation, wording, and the seed.test.ts path. See the inline comments.

(Written by Claude Opus 5.5)

Comment thread quest/m0/gate-headroom.md Resolved
Comment thread quest/m0/gate-headroom.md Resolved
Comment thread quest/m0/gate-headroom.md Resolved
Comment thread quest/m0/gate-headroom.md Resolved
Comment thread quest/m0/gate-headroom.md Resolved
Comment thread quest/m0/gate-headroom.md Resolved
Comment thread quest/m0/gate-headroom.md Resolved
Comment thread quest/m0/gate-headroom.md Resolved
Comment thread quest/m0/gate-headroom.md Resolved
Comment thread quest/m0/kix/inbox-accuracy.md Resolved
Count recent admissions against free memory as well as load, define the
spacing band, require atomic minute-long admission records, and pin down
the claim directory, clock-step, and Ctrl-C rules. The Ctrl-C fix covers
`quest worktree run` only if #178 has landed. The quest is
now [M]. Also fix the seed test path in the inbox-accuracy quest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated added a commit that referenced this pull request Oct 21, 2026
Before Linux 5.14 a scope's cgroup has no cgroup.kill, so leftover descendants were never killed and the supervisor waited on a populated scope forever. run now refuses such hosts up front, and kill() ignores a missing cgroup.kill only once the cgroup itself is gone, without ever creating the file. Retitle the worktree quest [M] and point the Ctrl-C follow-up at #180.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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: 5dfc30ea5b

ℹ️ 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 quest/m0/gate-headroom.md Resolved
Comment thread quest/m0/gate-headroom.md Resolved
Derive the recent-admission count from unexpired records with a
record-then-count step instead of slot numbers, which expiry leaves with
holes. Rewrite a future-dated record's time to now rather than discarding
it, so a large backward clock step still spaces admissions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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: 83b2c83a4a

ℹ️ 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 quest/m0/gate-headroom.md Resolved
Record-then-count prevents over-admission but can livelock when a whole
burst withdraws together. Suggest serializing prune, count, and record
under a short host-wide lock reclaimed from exited owners.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated added a commit that referenced this pull request Oct 21, 2026
…cally (#178)

* chore(quest): claim quest/m0/worktree.md

Quest-Claim: 4465a18959f4b93c

* feat(worktree): supervise runs in systemd scopes and release automatically

`quest worktree run <id> -- <command>` runs a job in a checkout inside a
systemd user scope named once per run. A handshake proves the shell is in
that scope's v2 cgroup before the supervisor lets the command start, so a
dead supervisor can never start it. When the command exits, descendants
left in the scope are killed, and once the scope is empty and no other run
remains, the scratch declared at `create` is pruned.

Runs are recorded before their scope exists. Every registry operation
reconciles runs whose owner (PID plus Linux start time) exited and whose
scope is empty, so a crashed supervisor's checkout is released only after
its orphans stop. A run that cannot be inspected or confirmed stopped stays
recorded and the checkout stays reserved, with the reason noted. `release`
refuses while runs are live. Non-Linux hosts fail explicitly.

The registry lock now names its owner in a file inside the lock directory
and is taken by an atomic rename, so the lock of a process that exited on
this host is reclaimed by unlinking that exact owner file, never a later
owner's lock.

Also: scratch is declared at `create` instead of `release`, a scratch
symlink to another worktree is unlinked rather than refused, and CI starts
a systemd user manager for the real-scope fixtures (orphan cleanup,
cancellation, crash reconciliation).

The quest now covers only `quest worktree remove`; the runner and agent
quests no longer wait on it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(worktree): refuse scratch naming the checkout on Windows

resolve('/', '.') is a drive root on Windows, so '.' passed the check
there and was refused only by the tracked-file check. Test the path's own
components instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(worktree): require cgroup.kill instead of waiting forever

Before Linux 5.14 a scope's cgroup has no cgroup.kill, so leftover descendants were never killed and the supervisor waited on a populated scope forever. run now refuses such hosts up front, and kill() ignores a missing cgroup.kill only once the cgroup itself is gone, without ever creating the file. Retitle the worktree quest [M] and point the Ctrl-C follow-up at #180.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
kixelated and others added 2 commits October 21, 2026 15:40
#178 landed, so the gate headroom quest fixes the double
Ctrl-C in both commands unconditionally, and the worktree quest links to
it instead of the planning PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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: 3201727034

ℹ️ 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 quest/m0/gate-headroom.md Resolved
Comment thread quest/m0/gate-headroom.md Resolved
Four review rounds kept finding edge cases in the prescribed records,
lock, and clock-step mechanisms. Keep the decisions and the three-band
rule, state what the admission mechanism must guarantee, and list every
review finding as a hazard the implementation must test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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: d8b6cc6ace

ℹ️ 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 quest/m0/gate-headroom.md Resolved
kixelated and others added 2 commits October 21, 2026 15:59
/run/user/<uid> comes and goes with logind sessions, so choosing by its
existence can split callers again. State the requirement and the
hazards instead of a directory rule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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: a8c6431b61

ℹ️ 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 quest/m0/gate-headroom.md Resolved
A SIGHUP sent with kill to Quest alone cannot be told apart from a
terminal hangup, so skip forwarding only SIGINT in the foreground group.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

@codex review

(Written by Claude Opus 5.5)

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: d3983e28c5

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: d3983e28c5

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@kixelated
kixelated merged commit d3d721c into main Oct 21, 2026
5 checks passed
@kixelated
kixelated deleted the quest/plan-gate-headroom branch October 21, 2026 23:36
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