Repository navigation
Worker-orbit maintenance: unforgeable triage dedup, broker self-reap, review-engine suite re-pin - #82
Conversation
…artifact footer decides GitHub's --search is full-text, so a forged <!-- feedback:<id> --> quoted inside another ticket (fenced raw feedback, or an injected diagnosis body) matched another row's duplicate lookup and silently dropped that feedback as already-ticketed (dp#59). findExisting now re-fetches each candidate and only trusts a marker sitting at the body/comment footer — the one position no user-derived text can reach, since registerTicket and commentOnIssue always stamp the marker as the artifact's last line.
A broker is workspace-scoped and spawned detached, so a session dying mid-run — or a review worktree being deleted — orphaned a live broker + codex app-server pair forever: the socket stays healthy and nobody who can reach that workspace's broker.json exists anymore (19h55m pairs observed live, dp#56). No outside sweep can reap those safely; whether anyone still wants a broker is knowledge only it has, since a client holds its connection open for as long as it is being served and the OS closes that socket the instant the client dies. So the broker shuts itself down — app-server child, socket and pid file included — after CODEX_COMPANION_BROKER_IDLE_TIMEOUT_MS (default 30min, 0 disables) with no client connection.
… owns The suite was dead on any machine without a system node (the PATH scrub that hides the real codex also hid node, rc=127 before the first assertion), and past that its stub codex still spoke the retired `codex exec review` transport while with-effort.mjs drives an app-server thread — assertions against a surface the engine no longer touches (dp#26). Rewritten to stub node itself: the pin is now the with-effort.mjs command line the engine composes (verb routing, defaults, the lens contract), its env recipe, rc mapping, and the fail-closed sandbox check — with no dependency on a real node or the thread protocol, which tests/codex-companion pins separately against a protocol-speaking fake codex. 34 assertions; three engine mutations (drop --wait, disable the sandbox fail-closed, invert lens precedence) each fail exactly their discriminating asserts.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7d98d7b992
ℹ️ 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".
| idleTimer = setTimeout(async () => { | ||
| if (sockets.size > 0) { | ||
| return; | ||
| } | ||
| await shutdown(server); |
There was a problem hiding this comment.
Stop accepting sockets before awaiting app-server shutdown
If a client connects after this zero-socket check but while shutdown() is awaiting appClient.close(), the listening server still accepts it; the broker then closes the app-server underneath that client and server.close() waits for the newly accepted socket, so an invocation arriving at the idle-timeout boundary can receive broken service and prevent the broker from exiting. Close the listener or mark the broker as shutting down before the first asynchronous shutdown step.
Useful? React with 👍 / 👎.
| if (sockets.size > 0) { | ||
| return; | ||
| } | ||
| await shutdown(server); |
There was a problem hiding this comment.
Clear the persisted broker session when self-reaping
After the idle timer calls shutdown(), it removes the socket and PID file but leaves the workspace's broker.json. A later work verb heals this through ensureBrokerSession(), but setup calls getCodexAuthStatus() with reuseExistingBroker and connects directly to the stale endpoint, so every normally reaped broker can make setup report a false authentication failure and suggest logging in again until another work verb runs. Remove or invalidate the persisted broker session as part of idle shutdown, or make diagnostic consumers probe and clear stale sessions.
Useful? React with 👍 / 👎.
| const value = Number(raw); | ||
| if (!Number.isFinite(value)) { | ||
| return DEFAULT_IDLE_TIMEOUT_MS; | ||
| } | ||
| return value > 0 ? value : 0; |
There was a problem hiding this comment.
Reject idle timeouts above Node's timer limit
When CODEX_COMPANION_BROKER_IDLE_TIMEOUT_MS is set above 2,147,483,647 ms—for example, a plausible 30-day retention value—this validation accepts it, but Node clamps the setTimeout delay to 1 ms with a TimeoutOverflowWarning. The broker then self-reaps almost immediately instead of honoring the requested long timeout, making normal clients race a continuously disappearing broker; reject or safely cap values outside Node's supported timer range.
Useful? React with 👍 / 👎.
| rc=0; PATH="$NODE_ONLY:/usr/bin:/bin" "$ENGINE" --base origin/main --out "$TEST_ROOT/out.txt" 2>/dev/null || rc=$? | ||
| assert_equals "$rc" "127" "missing codex CLI exits 127" | ||
| rc=0; PATH="$CODEX_ONLY:/usr/bin:/bin" "$ENGINE" --base origin/main --out "$TEST_ROOT/out.txt" 2>/dev/null || rc=$? | ||
| assert_equals "$rc" "127" "missing node exits 127" |
There was a problem hiding this comment.
Exclude system binaries from missing-dependency tests
On hosts where Node is installed as /usr/bin/node—a common Linux layout—the purported missing-node invocation still finds the real binary because /usr/bin:/bin remains in PATH, so the engine proceeds instead of returning 127 and this acceptance suite fails for reasons unrelated to the change. The missing-codex case has the same flaw when Codex is system-installed; build a minimal test PATH containing only the shell utilities and the one intended stub.
Useful? React with 👍 / 👎.
… trailing meta block The footer check added for dp#59 required the artifact body to END with our `<!-- feedback:<id> -->` marker, but the board renders its own meta block AFTER the body (_board.py compose_body), so any ticket carrying a park note or a spawned-by edge ends with `<!-- board:meta … -->` instead. findExisting refused those genuine tickets, and a retry after a failed DB writeback filed a duplicate. findExisting now strips one trailing board:meta block before the endsWith check. The regex refuses to cross a closer line, so a quoted fake block inside the prose cannot swallow the real footer — only the board's own trailer is ever removed.
…s new clients mid-shutdown The idle self-reap left the workspace's broker.json behind, and nothing that reads that record probes the endpoint: `status` kept reporting a live shared session and `setup`'s auth path dialled the dead broker and blamed auth, until some later work verb's ensureBrokerSession swept it. Shutdown now deletes the record, but only when it still names this broker — ensureBrokerSession may have already replaced it with a successor's. The listener also kept accepting while shutdown awaited appClient.close(), so a client arriving after the idle timer's empty-socket check got a connection that was in no end-loop, reached a closing app client, and could stall server.close. Such a connection is now destroyed on arrival, which the caller already handles as a probe failure and answers by respawning.
Both cases kept /usr/bin and /bin on the PATH, so on any host that ships the dependency they claim is absent — a Debian-family /usr/bin/node, a system-installed codex — the engine would find it and the case would assert nothing about the preflight it exists to pin. Each restricted directory is now the entire PATH, holding only the one stub being kept plus a symlink to the real bash. That is sufficient because both preflights are `command -v` builtins and both 127 exits happen before the engine runs any external command; bash is present only so the engine's `#!/usr/bin/env bash` shebang can resolve.
Independent review round 1 (codex native, gpt-5.6-sol) — 4 findings, all verified real, all adopted
Re-verified post-fix: triaging-feedback vitest 115/115 + tsc clean; codex-companion runtime suite 113/113 (incl. 2 new broker-record cases); review-engine suite all green (34); discriminance re-checked with the fixes reverted. |
…ailer opener Stripping a trailing board:meta block meant first FINDING its opener, and that is the ambiguity _board.py's meta_match exists to resolve. Quoted prose that leaves a bare `<!-- board:meta` line unclosed gave the leftmost opener a match running through the genuine feedback marker to the real trailer's closer, so the strip deleted the marker itself and a genuine ticket was refused. The check now anchors on the only trustworthy position, the last occurrence of the stamp, and asks whether everything after it is nothing but whitespace, at most one well-formed meta block, and end of string. Openers are never hunted, so unclosed, quoted, and legacy-nested ones cost nothing. A forged stamp in user content always has more prose behind it and still fails. The candidate search also carried gh's silent default of 30 rows: forged quote tickets can be minted one per feedback submission, and a genuine artifact ranked past the first page left the loop validating only forgeries. It now asks for 100.
…inst a boot-captured state path Refusing new connections did not make the broker undiscoverable: a prober's transport-level connect can succeed before the shuttingDown destroy lands, and the socket file and the record were only removed after appClient.close() and server.close(). ensureBrokerSession could therefore hand a caller a dying broker and the verb would fail instead of respawning. Both removals now happen first, before anything that awaits. The record clear also resolved its own path at reap time. The state directory is derived from the workspace root, so a workspace deleted mid-run — a review worktree, the case that produced these orphans — hashed elsewhere by then and the stale broker.json was never cleared. The path is captured at boot instead, which is why lib/broker-lifecycle.mjs now exports resolveBrokerStateFile. A sibling review finding asked for an atomic compare-and-delete on the record; declined, with the reasoning recorded at the call site.
Independent review round 2 (codex native, gpt-5.6-sol, on the round-1-fixed branch) — 5 findings: 4 adopted, 1 declined
Extra probe beyond the review: a forged Re-verified at HEAD: triaging-feedback vitest 117/117 + tsc clean; codex-companion runtime suite 114/114; review-engine suite all green; shellcheck clean. |
Three reliability fixes in the same worker orbit as PR #80.
dp#59 — triaging-feedback: the idempotency marker was forgeable
GitHub's
--searchis full-text, so a forged<!-- feedback:<id> -->quoted inside another ticket — in the fenced raw feedback, or in a prompt-injected diagnosis body — matched another row's duplicate lookup and silently dropped that feedback as already-ticketed.findExistingnow treats the search as candidate collection only: each candidate is re-fetched and trusted only when the marker sits at the body/comment footer — the one position no user-derived text can reach, sinceregisterTicketandcommentOnIssuealways stamp the marker as the artifact's last line. Footer verification also defends against injected markers outside the fence, which fence-stripping could not. Fail-closed behavior extends to the verification fetch. 5 new vitest cases; 113/113 green, tsc clean.Fixes #59
dp#56 — codex-companion: broker/app-server pairs self-reap after 30 idle minutes
A broker is workspace-scoped and spawned detached, so a session dying mid-run — or a review worktree being deleted — orphaned a live broker + codex app-server pair forever (19h55m pairs observed). The issue's preferred pid-file sweep can't reach these: their sockets are healthy, and whether anyone still wants a broker is knowledge only it has — a client holds its connection open for as long as it is being served, and the OS closes that socket the instant the client dies. So the broker reaps itself: no client connection for
CODEX_COMPANION_BROKER_IDLE_TIMEOUT_MS(default 30 min; unparseable falls back to the default so a typo can't resurrect the leak; explicit0disables) ⇒ clean shutdown taking the app-server child, socket, and pid file along. Same-workspace dead-socket records were already swept byensureBrokerSession; the two mechanisms compose. 3 new node:test cases (idle reap, held-connection service, disabled reaper); full runtime suite 111/111. SKILL.md/jobs.md leak prose updated to match.Fixes #56
dp#26 (delegated judgment) — the review-engine suite is re-pinned at the seam the engine owns
The suite was dead without a system
node(rc=127 before the first assertion) and its stub codex spoke the retiredcodex exec reviewtransport whilewith-effort.mjsdrives an app-server thread. Sincereview-engine.shis live and load-bearing for the qa-loops loop on main, the suite is rewritten rather than deleted — but the pin moves to the surface the engine actually controls: it now stubs node and asserts thewith-effort.mjscommand line the engine composes (verb routing, defaults, the lens contract), the env recipe, rc mapping, and the fail-closed sandbox check. The thread protocol stays pinned where it belongs, intests/codex-companion/against the protocol-speaking fake codex — so a future transport change can no longer rot this suite. 34 assertions, zero real-node dependency; 3 engine mutations each fail exactly their discriminating asserts.Validation
skills/triaging-feedback:npx vitest run113 passed,npx tsc --noEmitcleantests/codex-companion/run-codex-companion-tests.sh111 passedtests/qa-loops/test-review-engine.shall green (34); mutation-checked ×3tests/qa-loops/test-review-dispatch.sh,test-skill-entrypoint.sh,test-bootstrap-parity.shgreenscripts/lint-shell.shcleanscripts/bump-version.sh