Repository navigation
✨ crux: human gate service (S3) - #17234
Conversation
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. hive/awaiting-ci: CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 Review findings from Re-read at
Consequence is bounded: Still holds from OWNERS approval from — hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88 Review findings from Read the What I verified:
One small robustness note (info, not a defect): in
|
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of No conflicting open PRs or same-file overlaps were found. |
There was a problem hiding this comment.
Read src/crux/cli/gate.go, src/crux/cli/gate_test.go, src/crux/serve/gates.go, the Answer/Visible paths in src/crux/gates/service.go and authenticate in serve.go at fc8667a, plus the failing job logs, before the body. One verified defect, and it is in the test, not the service — it is why test (rest 3/4) / test (rest 4/4) are red.
TestGateOpenAnswerWait fails deterministically on the list assertion (medium — blocks CI, not a product bug)
src/crux/cli/gate_test.go:98-99comparesstring(list[0].Context) !={"pr":17}``, whereapi.Gate.Contextis a `json.RawMessage`.src/crux/cli/gate.go:114prints the list viae.writeJSON(list), which indents its output (the job log shows the record pretty-printed, with"context": {\n "pr": 17\n}).json.Unmarshalinto aRawMessagekeeps the source bytes verbatim, whitespace included, so after the round-tripContextis the indented form and the byte-equality check fails even though every other field in the log matches (answered_by: kelly,operator_override: true,note: green,opened_by: release-bot). All three CI retries fail identically atgate_test.go:100.- Fix is test-only: compare after
json.Compact, or unmarshalContextinto amap[string]anyand checkpr == 17. No change togate.goor the service is warranted for this.
What I verified in the auth path (no findings)
src/crux/gates/service.go:207—Answerrefuses any non-operator caller before touching the store; the CLI's first "self answer" step in the test relies on the override being refused by principal comparison, and the log confirms that step passed.src/crux/serve/gates.go:158-161—visibleGateruns beforesvc.Waitblocks, so a project principal cannot long-poll a gate it did not open.src/crux/serve/serve.go:201-207— a lane project credential is admitted only to work-service routes; agent RPCs still 401 it.gatesCaller(gates.go:46-51) treating an unauthenticated context as the operator mirrors the existingrunsbehaviour and is reached only on the unix-socket/no-token pathauthenticatealready permits.
Scope note: the diff is ~2.4k lines; I did not read store.go, wait.go, request.go or the two larger test files line by line, so this is not a full-coverage review of the service internals. The PR body's "Refs hivecommons/crux#114" with S4–S7 named as what remains is the right non-closing citation for a phased RFC.
I have not changed anything.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
The list output is indented, so the raw context carries whitespace and a byte-for-byte compare against the compact literal fails. Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
Shared CI incident: The PR-local hive/awaiting-ci: CI pending — sweep will merge when green. 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
There was a problem hiding this comment.
Correctness review (read at head 7e1bb925, which the PR moved to after dispatch at fc8667a2; go test is disabled in this pod, so this is read-only against the tree, CI still pending).
The gate state machine, idempotency scoping, crash ordering (resolved-before-pending-remove in src/crux/gates/store.go:60-80, reconciled by dropStalePending in service.go:62-70) and the watcher/expiry wake-ups in wait.go hold up; the -race-relevant paths all take s.mu and emit runs outside it. Tests cover restart, visibility, self-answer, expiry and the long-poll window.
One advisory, non-blocking:
gates.Newabortscrux servestartup on one unreadable gate record (low).store.list(src/crux/gates/store.go:103-125) returns the firstreadRecorderror ("corrupt record"),Newpropagates it (src/crux/gates/service.go:56-60), andcmdServeturns that intoExitError(src/crux/cli/serve.go:137-141). Writes are atomic via rename so this needs an external edit or disk fault, but one badpending/<id>.jsonthen takes the whole server — including runtime/agent routes — down, with no way to serve the other gates. Suggest skipping (and logging) or quarantining unreadable records inlistrather than failingNew.
Info only: normalizeContext checks MaxContextBytes on the pre-scrub encoding and then stores the scrubbed re-encoding (src/crux/gates/request.go:94-99), so a stored payload can slightly exceed 64 KiB when a redaction marker is longer than the credential it replaces. Harmless; noting for completeness.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
|
Test-review of Crash recovery between the two writes is never exercised.
Suggested test (fits the existing fixture): func TestRestartDropsPendingCopyLeftByCrash(t *testing.T) {
f := newFixture(t)
g, _, _ := f.svc.Open(driver, Request{Subject: "crash me"})
if _, err := f.svc.Answer(operator, g.ID, Answer{Choice: "approve"}); err != nil {
t.Fatal(err)
}
// Simulate a crash after the resolved write but before the pending remove.
resolved := filepath.Join(f.dir, ResolvedDirName, g.ID+".json")
pending := filepath.Join(f.dir, PendingDirName, g.ID+".json")
stale, _ := json.Marshal(Record{ID: g.ID, Status: StatusWaiting, OpenedByPrincipal: driver.Principal})
if err := os.WriteFile(pending, stale, 0o600); err != nil {
t.Fatal(err)
}
f.restart()
if _, err := os.Stat(pending); !errors.Is(err, os.ErrNotExist) {
t.Fatalf("stale pending copy survived restart: %v", err)
}
if rec, err := f.svc.Get(operator, g.ID); err != nil || rec.Status != StatusAnswered || rec.Answer != "approve" {
t.Fatalf("resolved record must win after crash: %+v %v", rec, err)
}
_ = resolved
}(Adjust 🐝 Hive Agent: — hive: agent=quality backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
🛑 Fix loop escalated — human attention neededThis PR has failed CI on 3 distinct fix attempts (new commits, still red). The hive has stopped dispatching further automated fixes for it. Failing checks: coverage Raw failure evidence (from check-run annotations): Remove the |
|
The hive's GitHub App lacks |
|
Needs a decision, not a merge: Clear the cause and the hive re-evaluates on its next pass; the stage moves to |
|
Diagnosis of the remaining red check (
Everything else is green (all test shards, lint, gosec, govulncheck, DCO). The gap is the new Not pushing here: the PR is in the escalated fix loop ( 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
The coverage gate put crux/gates at 83%, crux/api at 87% and crux/cli at 91% against floors of 90, 90 and 92. Exercise the request bounds, id shape, default clock and id minting, the crash ordering between the resolved and pending copies, corrupt and stray records, and journal and directory failures in gates; drive the typed gates, checkouts and runs client methods against a recording fake in api; and cover the --json outputs, the list table, --timeout on wait and the typed failure codes in the CLI. No sleeps: the one timed wait is a 50ms context deadline. Signed-off-by: Andrew Anderson <andy@clubanderson.com>
There was a problem hiding this comment.
Decision needed: @kellyaa should decide whether the S3 gate service (new gates package, /v1/gates routes, crux gate verb — 2.9k lines) is in scope to land now against crux#114's phase-2 sequencing, and whether gate.* events should carry note (code does) or not (design doc says not).
Conclusion: the core gate machinery reads correctly to me; I found one verified code/doc disagreement about what the gate.* events carry. Landing a 20-file XXL feature slice of crux#114 is a scope call for the requester, not something I can settle.
What I read (head 283baeb, cloned): gates/service.go, gates/wait.go, gates/store.go, gates/request.go, serve/gates.go, serve/principal.go, serve/runs.go, both docs.
Verified correct:
- Resolution durability:
store.put(gates/store.go:61-80) writesresolved/<id>.jsonvia rename before removingpending/<id>.json;store.get(:83-95) andstore.list(:99-127) prefer the resolved copy, andNew(service.go:66-72) drops the stale pending file on restart. The crash-ordering claim holds. - Answer authorization:
Service.Answer(service.go:206-208) refuses non-operators before any disk read;answerLocked(wait.go:50-56) comparesOpenedByPrincipalto the authenticated principal, not the caller-suppliedopened_by; exact-replay returns the record unchanged, other answers to a closed gate returnErrClosed→ 409 (serve/gates.go:200). - Visibility:
visibleGate(serve/gates.go:170-182) gates Get/Wait ongates.Visible; List passesCallerso project principals see only their own gates (service.go:174).workService(api.PathGates)uses prefix matching (serve/principal.go:78-85), so/v1/gates/{id}/answeris admitted to project principals and then rejected byAnswerwith 403 — consistent with the stated design. - Wait: the expiry branch (
wait.go:36-45) loops back toloadLocked, which callsexpireLockedand wakes watchers viaresolveLocked; no background goroutine, notime.Sleep.gatesCaller's unauthenticated→operator fallback (serve/gates.go:46-52) mirrorsrunsCaller(serve/runs.go:18-24). - Scrubbing: subject,
opened_by, context string leaves and note all passlogscrub.ScrubString(gates/request.go:30,35,123,144); context is capped atMaxContextBytes(:101).
Finding (low) — events carry note, docs say they do not. publishGate (serve/gates.go:219-221) only clears ev.Context; gateToAPI (:234) copies rec.Note, and api.Gate.Note is json:"note,omitempty" (api/gates.go:97), so every gate.answered event includes the note when one was given. src/docs/design/crux-work-services.md:220 states "Events and the journal never carry context or note", and the PR body repeats it; src/docs/crux-serve.md:178 says only "without its context". The journal half is true (JournalEntry has no note field, store.go:23-32). Either ev.Note = "" next to ev.Context = nil, or correct the design doc — the two docs should agree with the code and each other. The existing event test (serve/gates_test.go:162-187) checks event types only, so it would not catch this.
Not a defect, for the record: native-queue-policy is red with head/base moved, draft, closed, or held — a queue-policy replay, not a code failure.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
clubanderson
left a comment
There was a problem hiding this comment.
Matches RFC crux#114 S3: gates package seam, crux gate verb, /v1/gates routes, toolapprove-style idempotency scoped to the opening principal, constrained answers, audited as_operator override, expiry as its own status, injectable clock with no sleeps, changelog fragment. Pushed 283baeb to lift the coverage floors (gates/api/cli) and linked the RFC as Part of. needs-human/hive:unauthorized were the bot lacking actions: write to rerun CI, cleared.
/lgtm
/approve
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: clubanderson The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
LGTM label has been added. DetailsGit tree hash: d9c32ac97f0ee560448d7a778f69ea7af222aef6 |
Review follow-ups (below
|
|
Thank you for your contribution! Your PR has been merged. We'd love to hear how your experience was: share feedback |
Part of hivecommons/crux#114 (S3 of seven work services; S4 command log, S5 turn signals, S6 schema-checked agent step and full S7 remain and are sequenced after this per the RFC)
Why
The RFC puts S3 alongside S7-minimum and S4 in phase 2 because the Nous adapter needs a recorded human decision before it spends money or trusts a finding.
toolapprovealready has the persistence shape (durable inbox, derived idempotency key, decision journal). Until now nothing in crux could open or answer a gate. This PR adds agatespackage that follows that shape and exposes it in the three required ways: a Go seam, thecrux gateverb and/v1/gatesroutes.Design choices
toolapprove.DeriveIdempotencyKey, scoped to the opening principal. The key covers subject, canonically re-encoded context (sorted keys, so{"b":1,"a":2}and{"a":2,"b":1}count as the same gate), choices, timeout andopened_by. Timestamps are never part of it. A caller-suppliedidempotency_keyreplaces the content hash when present. Scoping to the principal means a project cannot read another project's gate by guessing its key.opened_bylabel. So an operator-opened gate needsas_operator(--as-operator). That override is recorded asoperator_override, written to the journal, and emitted asruntime.auditwith actiongate.operator_override(forwarded toAuditSinkwhen one is set).choices, otherwise you get 422gate_invalid_choice. Free text goes only innote. Retrying the exact recorded answer returns 200, so a lost response is safe to retry. Any other answer to a closed gate gets 409gate_closed.expired_at. Expiry is applied on read (Get, List, Answer, Wait), and a waiter's own timer flips the gate at its deadline. There is no background goroutine.gate_context_too_large413,gate_invalid_choice422,gate_self_answer403,gate_closed409). Every other case reuses the existingbad_request/forbidden/not_found/not_supportedcodes in the same sense they already have.opened_byand every string leaf insidecontextgo throughlogscrub.ScrubStringbefore they are stored.gates.jsonland thegate.*events never carrycontextornote, so tailing the journal or the event stream does not leak what a gate is about.resolved/<id>.jsonbefore removingpending/<id>.json. If the process dies between the two, the resolved copy wins on the next start.Config.Now) and an injectableAfterand never calltime.Sleep.Where this diverges from the spec, and why
Server.HandlerviaregisterGates, next toregisterCheckoutsandregisterRuns, not insideregisterFamilies. The merged S1 and S2 code already does it this way:registerFamiliesholds thecrux.Runtimefamilies, and the work-services families mark their prefix withworkServiceso project principals are admitted.crux gateis remote-only, likeruns. It is not local-plus-remote likecheckout. The server is the single writer that knows principals, journals decisions and publishes events, and a second in-process writer on the same work dir would bypass all three. It is exempt fromRuntimeVerbs, added to thenonRuntimeVerbstest set, and listed incrux help.gate.expiredevent alongsidegate.openedandgate.answered. Without it, a dashboard could not tell an expiry from a gate that is still waiting unless it polled.answer, to match the record. The CLI flag stays--choice, as in the spec.crux gate waitloops over these polls, with an optional overall--timeout.Deferred
waitingon disk past its deadline until the next read, which then expires it and emits the event.--server)crux gate.Docs
src/docs/crux-serve.mdgets a route-table row and an events row.src/docs/design/crux-work-services.mdgets a new S3 section (routes, codes, semantics, storage) and package-map rows. The changelog fragment ischangelog.d/added-crux-gates-s3.md.Only
gofmt -lwas run locally; CI is the verdict.Opened by scanner (hive agent) implementing the next sequenced RFC slice.
— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 requested_by=@kellyaa