Skip to content

Read the merge queue's notes in one git process so land and ready stay fast (GST-2198) - #4242

Merged
capy-ai[bot] merged 3 commits into
mainfrom
capy/read-queue-notes-in-one-batch-gst-2198
Nov 9, 2026
Merged

capy-ai[bot] merged 3 commits into
mainfrom
capy/read-queue-notes-in-one-batch-gst-2198

Conversation

@garrytan

@garrytan garrytan commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

gstack-ship-queue land --pin and the first ready on a head now read the merge queue's notes with one git process instead of one per note. This keeps the merge step fast and stops it from drifting toward the command timeout, which serves the goal of a merge queue crews can rely on.

What changed

Rebuilding local queue state from refs/notes/gstack-trains (rebuildFromNotes in crew/lib/ship-queue-train-record.ts) ran git cat-file blob once per note. It now feeds every note blob to a single git cat-file --batch process and splits the output by byte size before decoding, so notes with multibyte text come back intact. Each note still goes through the same parseNote, in the same order, so the same records are restored. Malformed, empty and wrong-schema notes are still skipped.

Measured on the live 1,442 notes (a bare fetch of refs/notes/gstack-trains, same 4-core machine):

first rebuild (empty state) later rebuilds
before 14,781 ms 15,435 ms, 14,103 ms
after 505 ms 137 ms, 118 ms

Both runs restored 1,442 records, and the restored state directories hash the same (ac7b69ad8ba24d70).

Why

Every land and every first READY paid that 14 to 15 s cost, and it grew about 8 s a week as notes piled up. At that rate it would pass the 120 s git command timeout in about three months, and a land killed there leaves the land lock held (reports/GSTA-461.md item 4).

Blast radius

One function in crew/lib/ship-queue-train-record.ts, plus parseNote is now exported so the test can run the old per-note read as its oracle. No output, result code or record format changed. One behaviour is stricter. If that single read fails, times out or overruns its buffer, the rebuild now reports the notes as not read (fetched: false), so land --repair and the freeze lock refuse instead of acting on an empty queue.

Tests

New crew/test/ship-queue-notes-batch.test.ts, on a fixture of several hundred notes that includes a malformed note, an empty note, a wrong-schema note, a multibyte note, a note whose text looks like a cat-file header, and a duplicated record:

  • The batch reads all notes with one git cat-file process. This failed on main with 411 processes.
  • The batch restores exactly the records the per-note read restores.
  • A newer local record is kept, a repeat rebuild restores nothing, and an origin with no notes reads nothing.
  • A failed batch read reports fetched: false and restores nothing (failed before the fix in c089dee).
Agent notes

Lane GSTA-469 for GStack Minder (GSTA-36), issue GST-2198. /ship by its /ship subagent at head 29cdc70.

Plan: exempt: bug fix

Bug fix under R65; the failing-first test was written on origin/main f75ce6f.

Checks

  • CI_CARRY: accepted ci-carry tree=7566bc6cb3ca tests=36882 runs=42700455540/1 profiles=ci-reuse/free-tests heads=29cdc707dee3
  • PREGATE: requires-remote cleared tree=7566bc6cb3ca head=29cdc707dee3 checks=8 (macos-named-regressions cleared by run 42700455540 attempt 1)
  • Lanes: notes pass tests_ran=4, queue pass tests_ran=98. evals: none affected.

Review

  • REVIEW_LOOP: passes=2 blocking_found=0 deferred=0 noted=1 fixed=2 scope=frozen ledgers_read=2 dispatches=4
  • Pre-Landing Review (pass 1): 2 issues — 2 auto-fixed, 0 asked, 0 deferred, 0 noted. Pass 2: no issues in the diff, notes below.
  • Gate edits: none detected (1 listed, 0 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)
  • Adversarial (Step 11): native adversarial issues_found (3 notes below, none blocking); outside voice openai/gpt-6.1-sol CLEAN.
  • Exploratory QA: pass. A failed git cat-file --batch was reproduced reporting fetched:true with 0 of 51 notes read; after the fix it reports fetched:false and writes no record.

Review notes

Below the blocking floor (advisory, informational, test-gap or wording items); recorded here and not fixed in this PR.

  • INFORMATIONAL lib/ship-queue-land-direct.ts:161 A normal direct land (land-direct:161/173) and newTrain (train.ts:404-405) ignore rebuildFromNotes().fetched and read the freeze from local JSON, so a failed notes read (fetch or, now, the batch) lets a non-repair land past a remote-only freeze. Pre-existing for fetch failures; the :229 refusal text says 'cannot fetch' when the cause may now be the batch read.

  • INFORMATIONAL crew/lib/ship-queue-train-record.ts:389 A failed git notes list (timeout, maxBuffer, corrupt notes tree) after a good fetch still returns fetched:true with nothing read, the same fail-open shape the batch fix closed; land --repair could then judge the repair slot from stale local freeze files. Unchanged line.

  • INFORMATIONAL lib/ship-queue-land-direct.ts:229 The land --repair refusal says 'cannot fetch' and drops rebuildFromNotes().detail, though fetched:false can now mean the cat-file read failed after a good fetch.

  • INFORMATIONAL lib/ship-queue-land-direct.ts:161 Most rebuildFromNotes callers (train-verify, train, wave, train-ready, train-forget, land, land-direct:161) ignore fetched:false and carry on with local records; pre-existing for fetch failures; a policy call outside this diff.

  • INFORMATIONAL crew/lib/ship-queue-train-record.ts:389 (adversarial) A failed git notes list after a good fetch still returns fetched:true; unchanged line, one-line follow-up.

  • INFORMATIONAL lib/ship-queue-land-direct.ts:229 (adversarial) The repair refusal says "cannot fetch" and drops rebuildFromNotes().detail.

  • INFORMATIONAL lib/ship-queue-land-direct.ts:161 (adversarial) Most rebuildFromNotes callers ignore fetched:false (pre-existing for fetch failures; policy call).

Documentation

Status: current. No documentation edits needed.

Scope: base f75ce6f..head c089dee plus the unstaged changelog fragment: crew/lib/ship-queue-train-record.ts (notes rebuild now reads every note with one git cat-file --batch call and fails closed), crew/test/ship-queue-notes-batch.test.ts, changelog.d/capy-read-queue-notes-in-one-batch-gst-2198.md.

Documentation health:

  • docs/ship-policy.md: current (notes-ref mirroring described at the behaviour level, still accurate)
  • docs/troubleshooting.md: current
  • docs/releases.md: current
  • crew/docs/captain.md: current
  • changelog.d fragment: reviewed, not edited (parent owns it)

Coverage debt: none. No new commands, flags, environment variables or skills.

Diagram drift: none.

Open in Capy

Agent notes
{
  "schema_version": 1,
  "pr": 4242,
  "head": "29cdc707dee3ae6d2405f3b5f063628c2cd3cf3f",
  "version": "1.98.0.0",
  "base": "main",
  "session_kind": "unattended",
  "head_tree": "7566bc6cb3ca4b8c044f382c09f151dc3ef71da5",
  "product_patch_id": "6d742599def9e5f1d4c1206f3eead0b0fb014dcb",
  "gstack_version": "1.98.0.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 30,
    "rules": "66e5174161eecc2c",
    "base": "f75ce6fdcc14e6398b00645c1608e834d766a922",
    "registry": "f75ce6fdcc14e6398b00645c1608e834d766a922",
    "gate_scan": {
      "tagged": 0,
      "head": "29cdc707dee3ae6d2405f3b5f063628c2cd3cf3f"
    },
    "reasons": [
      "gate-class",
      "risk:security",
      "runtime=30"
    ],
    "risk": [
      "security"
    ],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @7566bc6cb3ca (8 checks, current for 29cdc707dee3)",
  "requires_remote": [
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/42700455540/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=7566bc6cb3ca tests=36882 skipped=68 runs=42700455540/1 profiles=ci-reuse/free-tests heads=29cdc707dee3 verified=2026-11-09T21:40:33.877Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "docs/, crew/docs/, README.md (f75ce6fd..c089deec plus changelog fragment)"
  },
  "review_loop": {
    "passes": 2,
    "blocking_found": 0,
    "deferred": 0,
    "noted": 1,
    "fixed": 2,
    "scope": "frozen",
    "rounds": 2,
    "ledgers_read": 2,
    "dispatches": {
      "specialist": 2,
      "red-team": 2
    }
  }
}

…y fast (GST-2198)

Rebuilding local queue state from refs/notes/gstack-trains ran one git cat-file per note: 14 to 15 s per land and first ready on the live 1,442 notes, growing about 8 s a week toward the 120 s command timeout. One git cat-file --batch now reads them all (about 120 ms on the same notes) and restores byte-identical records.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@trunk-io

trunk-io Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 2 commits November 9, 2026 20:55
… queue (GST-2198)

When the one git cat-file --batch process fails, times out or overruns its buffer, rebuildFromNotes now returns fetched:false, so land --repair and the freeze lock refuse instead of reading no notes. The test's counting git shim now execs the git in git --exec-path, so a PATH git wrapper cannot loop back into it.

Review-Finding: p1/red-team#1 reader=red-team
Review-Finding: p1/red-team#2 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot merged commit 01e3980 into main Nov 9, 2026
50 checks passed
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