kunibert
All repositories: gitoria
13.8 KB
# K7: one service, event → posted review (kunibert#7)Everything ran against FAKES: K6's fake gitoria (copied and extended), a fake codex on PATH, `file://` for git fetch (Basic auth over HTTP(S) for git is NOT exercised), local ports 8841 (fake gitoria) and 8842 (service). No real gitoria, no real codex, no commits, no tickets. Every process I started was stopped by PID (proof output last line).## FilesScratch: `/media/STORAGE/claude-scratch/kunibert/K7/` (`scripts/proof.py`, `scripts/fake_gitoria.py`, `bin/codex`, `proof-output.txt`, `svc.log`, `fake.log`, `calls/NN` = what the fake codex received, `config.json`, `repos.json`).Hybriel .hl (all in lib/, tools/, service/):- `lib/run-job.hl` REWRITTEN. `runJob(job, done)` builds the argv and starts the CLI as a child with `spawnArgs`, then returns at once. `on child.line` collects stdout/stderr, `on child.exit` calls `done({ok, error, out})`. A `hl:time` `after(timeoutSeconds)` timer kills the child (`child.kill()`, SIGTERM); the job counts as failed. A killed CLI cannot post the status, so the service starts a short second child (`status-error`) that PUTs `error` for `job.head`. `dropSession(mark, number, done)` runs `drop`. The old record-only behaviour with its test hooks stays as `legacy` when no repos are configured (K5 phase tests).argv: `hybriel tools/runner.hl review-pr <runnerData> --api A --key-file F --clone C [--force] [--reset] [--note-file f] <pr>`; `--force` for force/reset/notes jobs.- `lib/queue.hl`: `tick()` only STARTS one thing and returns (a drop of a closed PR's session first, otherwise the oldest startable job). New completion call `done(key, result)`: success removes the job or promotes `next`; failure → retry/backoff/`failed` as before (`settle` unchanged). `busy` flag = one child at a time. Drop: the mark gets `removeSession=false`, `removed=<time>` (the record itself stays so a late `synchronize` of a closed PR is still ignored; `/health.sessionsToRemove` becomes empty).- `lib/intake.hl`: per-repo config (`reposFile`). The secret per repo is read from `secretFile` (mode 600 checked), the key file mode is checked at start. After the signature check, an event whose `repo.id` is not configured or whose `repo.api` / `repo.clone` differ from the config → 403 `repo_mismatch`, logged without any secret (and the delivery is not marked seen). Unknown repo id → no secret → 401.- `lib/gitoria-events.hl`: `@kunibert reset` and `@kunibert <text>` set `force` (so the review POST is not suppressed by rule (d)).- `lib/runner.hl`: `reviewGitoria(..., forced, doReset, notes)`: `reset()` first (generation+1, session dropped), then `addNotes` (author notes into the state's `pending`, de-duplicated on retries), then the review. A FRESH-session prompt now also carries the pending notes (before, only the wake prompt did).- `lib/review-memory.hl`: new `drop(data, repo, pr)` (removes the state file), `addNotes(...)`.- `lib/review-wake.hl`: one line in `rules` (included in the first-review prompt, the wake prompt and the fallback prompt, so each prompt has it once): never write suggestion blocks, write a fix as a normal code block with a language tag. (The line avoids the literal fence, see DOCS.)- `tools/runner.hl`: `review-pr` takes `--reset` and `--note-file <json [{text,by}]>`; new forms `drop <data> <clone> <pr>` and `status-error --api --key-file --head <sha> [--message]`.- `service/project.hl`: passes `reposFile`, `hybriel`, `jobTimeoutSeconds` (default 900), `runnerData` (default `<dataDir>/runner`); `secretsFile` is now optional.Service config: `{port, dataDir, tickSeconds, maxTries, backoffSeconds, reposFile, hybriel, jobTimeoutSeconds, runnerData, secretsFile?}`.reposFile: `{"<repo.id>": {"api", "clone", "keyFile", "secretFile"}}`.## Commands```# the proof (starts and stops fake gitoria + service itself; env HL_ENV=production, PATH with the fake codex)cd /media/STORAGE/claude-scratch/kunibert/K7 && python3 -I scripts/proof.py > proof-output.txt # ends with ALL OK# the service by handcd /media/STORAGE/projects/kunibert && HL_ENV=production /media/STORAGE/projects/hybriel/native/zig-out/bin/hybriel service <config.json># regression, all ALL OK / exit 0 after my changescd /media/STORAGE/claude-scratch/kunibert/K4 && python3 -I proof.pycd /media/STORAGE/claude-scratch/kunibert/K6 && python3 -I scripts/proof.pypython3 -I /media/STORAGE/claude-scratch/kunibert/K5/tests/proof.py phase1 # also phase2, phase3```(Rerun outputs: `K4/proof-output-k7rerun.txt`, `K6/proof-output-k7rerun.txt`, `K5/proof-phase{1,2,3}-k7rerun.txt`. K5 phase 4 was not asked and is superseded by the live follow-up proof below.)## Proof output (K7/proof-output.txt, every line PASS, ALL OK; excerpts)Intake:```PASS signature made with repo 2's secret on a repo 1 event -> 401 bad_signaturePASS repo.clone differs from the config -> 403 repo_mismatch, refusedPASS unknown repo id signed with a known secret -> 401signed non-JSON body -> 500 '500 Internal Server Error'PASS GAP hybriel#280: 500 (not 400) but HL_ENV=production: the body names no file pathPASS draft PR -> ignored; no request reached gitoria for refused/draft events```Opened PR1 with a slow (5 s) fake codex, /health during the run, synchronize as follow-up:```POST pull_request.opened PR1 -> 202 queued 1#1/health during the run (10 polls): min 1.1 avg 2.3 max 3.7 ms; running=1#1POST pull_request.synchronize PR1 -> 202 {"status":"follow-up","job":"1#1"}fake gitoria writes (request log):PUT /statuses/<head1> (pending)POST /pulls/1/reviews (head1; ONE inline comment a.txt:15; the off-diff finding in the body)PUT /statuses/<head1> (failure)PUT /statuses/<head2> (pending) <- the follow-up, runs after run 1 endedPOST /pulls/1/reviewsPUT /statuses/<head2> (failure)svc.log: worker: done 1#1 / worker: follow-up for 1#1 queued: head=<head2> / worker: start 1#1 head=<head2>state: head=head2, session=fake-session, T1 gid th1inline body: '**🛑 Blocker · Correctness: Bad change**\n\nFix it.\n```\nx\n```' (the model's suggestion fence came back as a normal fence: K6 rewrite)```review_comment from a user, same head (threadReplyOnly=true):```POST review_comment.created PR1 -> 202 queued threadReplyOnly:truewrites: POST /pulls/1/threads/th1/replies, POST /pulls/1/threads/th1/resolve (no review, no status)prompt: contains the reply and "No new commits since your last review" (the existing unchanged-head path)```Reset and note:```@kunibert reset -> runjob force=true reset=true; fake codex argv has no `resume`; prompt "Review pull request ..."; generation 0 -> 1;writes PUT pending, POST review, PUT failure@kunibert check the db code -> runjob force=true notes=1; the prompt the fake codex got has the line"Note from Bob (@kunibert): check the db code"; pending cleared after the run; review posted```Closed:```POST closed PR1 -> 202 closedsvc.log: worker: removing the session of closed 1#1 / worker: session of 1#1 removed, mark clearedstate file gone; no model run, no gitoria request; /health sessionsToRemove: []; a later synchronize -> ignored```Hanging codex (config `jobTimeoutSeconds` 8, maxTries 2, backoff 2 s):```PR2 opened, fake codex sleeps; /health max 2 ms during the hangrunjob: 1#2 KILLED at timeout, error status exit=0 (8.5 s after start)status: {'state': 'error', 'summary': 'Review timed out after 8s', 'context': 'kunibert'}the hanging codex pid is gone (killed with its parent by PDEATHSIG)worker: 1#2 failed (Review timed out after 8s), try 1/2, retry in 2s -> second try, killed again ->OPERATOR: job 1#2 FAILED after 2 tries: Review timed out after 8swrites: 4 status PUTs (pending, error per try), no review, no comment```Secrets: the key, both secrets and 13 tokens were grepped in svc.log, the whole data dir (state, git cache, queue), all codex call dirs and the fake's stdout: no hit.## Answers to the mission questions- Thread flips (`review_thread`): the queue stores/merges them and triggers nothing; the run reads thread state from gitoria's threads at run time. Confirmed by design and by K6 proof s5 (resolved comes from `thread.resolved`); not separately exercised through the service.- threadReplyOnly: confirmed live (see above): same head + user reply → the existing "unchanged head → thread replies only" path (no pending status, no review POST).- Draft and skipped runs post nothing: confirmed (draft event: no gitoria request; the skip path is K6 s2).- Contract v1.2 in the fake: I changed the fake so a review for an EARLIER head is accepted (409 only for a sha that was never a head of the PR). This was needed for the follow-up proof: run 1 posts for head1 while head2 is already the PR head. Posting for the reviewed head (K6 (b)) worked unchanged.## DOCS lines- DOCS: a nested `on child.line` / `on child.exit` / `on timer.tick` INSIDE a function (not only at the top level) works and may call a closure passed in (used in `runChild`). The primer only shows top-level `on`.- DOCS: a backtick template literal cannot contain a backtick, and there is no escape (a prompt line with three backticks broke the file with "suggestion blocks is two statements on one line"). The primer should say so.- DOCS: `x = null` for an uninitialised local is "Cannot reassign immutable variable"; it needs `let`. There is no `??` operator (I wrote a small `opt(v, d)`).- DOCS: `child.kill()` is SIGTERM only; no way to escalate to SIGKILL, and the exit event reports 143.## GAP lines- GAP 3 of K5 (blocking worker): resolved by `spawn`/`on exit`. With a child running (slow 5 s, hang 8 s) /health answers in 1–4 ms and the follow-up path runs live. The earlier uncertainty about `run()` blocking is hybriel#282.- GAP 2 (hybriel#280): a signed (or, with per-repo secrets, any) body that is not valid JSON gives HTTP 500 instead of 400; with `HL_ENV=production` the body is a plain `500 Internal Server Error` without a path (proved). Still 500 until #280. No workaround. Note: the service's OWN log (stdout) still prints the located error line (`Runtime error: …/lib/intake.hl:78:16: JSON.parse: invalid JSON`), which is fine for an operator log but contains a path.- GAP 1 (hybriel#281): the signature compare is still `!=` (not constant-time).- No new framework gap.## Open points- The timeout kill is SIGTERM to the CLI (`hybriel`); the fake codex died with it (PDEATHSIG). A real codex that spawns its own helpers may need the same. A worktree of a killed run stays until the next run of that PR removes it (K4 stale-removal). No SIGKILL escalation is possible (see DOCS).- The timeout status `error` is posted by a second short child for `job.head` (the head of the event). If the PR head moved meanwhile, the error lands on the older head; a following run sets its own status.- After the kill the job is retried (maxTries) and is then `failed`; the PR keeps the last `error` status. A new event re-queues it (K5 rule).- The drop only removes the session state file; the git cache of the repo stays (shared by all PRs).- With per-repo secrets the body is parsed before the signature check (K5 GAP 2): garbage gives 500 even when unsigned.- A fresh review after `@kunibert reset` keeps the old thread ledger of the state (K3 behaviour, unchanged); `reset` only drops the session and the pending notes.- Notes are put in the state's `pending` before the run; a failed run keeps them for the retry (de-duplicated). A note sent while a job runs becomes a follow-up job's note.- Limits not tested: `repo.api` comparison is an exact string compare (trailing slash, http vs https must match the config); closed-while-running (code path exists from K5, not exercised live).- `reposFile` and per-repo secret files must be mode 600; the service refuses to start otherwise.## Real proof on kunibert-test, once gitoria is live1. On the machine of the service: create the key file (mode 600) with the app key and a secret file (mode 600) with the webhook secret gitoria uses for that repo. Write `repos.json`: `{"<repo.id>": {"api": "<exactly the repo.api in the events>", "clone": "<exactly the repo.clone in the events>", "keyFile": "/abs/key", "secretFile": "/abs/secret"}}`. Take both strings from one real delivery (they must match exactly).2. Config: `{"port": <free port>, "dataDir": "/abs/svc-data", "tickSeconds": 3, "maxTries": 3, "backoffSeconds": 30, "reposFile": "/abs/repos.json", "hybriel": "/media/STORAGE/projects/hybriel/native/zig-out/bin/hybriel", "jobTimeoutSeconds": 900, "runnerData": "/abs/runner-data"}`; the real `codex` must be on PATH of the service.3. Start: `cd /media/STORAGE/projects/kunibert && HL_ENV=production /media/STORAGE/projects/hybriel/native/zig-out/bin/hybriel service /abs/config.json > svc.log 2>&1 &` (note the PID); `curl http://127.0.0.1:<port>/health`.4. In gitoria register the app webhook for the repo to `https://<host>/hook/gitoria` with the same secret (events: pull_request, review_requested, review_comment, pull_comment, review_thread).5. On kunibert-test open a PR with a small, obvious bug → expect in `svc.log`: `hook: 202 queued`, `worker: start`, `runjob: … start`, `worker: done`; in gitoria: status pending → review with inline comment → status failure/success.6. Push a commit while the review runs → `follow-up` and a second review after. Comment `@kunibert check <something>` and `@kunibert reset`; reply to a Kunibert thread; resolve one; close the PR → `session … removed, mark cleared`.7. Check `/health` stays fast during a review; check that no key/secret/token is in `svc.log` or the data dirs (`grep -r`).8. Stop the service by its PID (`kill <pid>`); the CLI children die with it.Things to verify that the fakes could not: Basic auth for git fetch of `refs/pull/N/head` over HTTPS (K4 fix 1), the real event names/field paths (only `lib/gitoria-events.hl` changes), real review/status route names (only `lib/gitoria-api.hl`), that `repo.api` / `repo.clone` in real events equal the config strings.
Branches
Latest commits
- bd3591c7conductor: gates run on the live day44 binarymre
- 47f747a7records: jukebox #9 fix livemre
- 0a3169fdMerge branch 'vendored-size' into mainKunibert
- e447bb09Vendored size fix: keep renames with an app side whole; type the filter parameter (L10)mre
- 99ccc742Vendored size fix: no renames in the app diff, filter the resumed delta toomre
- 1a52e100|||PR Diff size limit counts only app files when vendored paths are setmre
- 50a1867estatus: jukebox #9mre
- c57484e6log: jukebox #9 diff sizemre
- 795a20carecords: guard fix live (PR 8)mre
- 6981d96fMerge branch 'fresh-on-nocmd' into mainKunibert
- 37c47840runner: one shared prompt for both fresh-session fallbacks (L16)mre
- f945d2e1|||PR runner: a resumed run with no command on a new head gets one fresh session instead of a tool errormre
- 10b2a49estatus: PR 314, guard fix proposedmre
- e73995a3log: hycon PR 314 approved after fresh reviewmre
- f60427falog: hycon PR 314 false tool errormre
- 481974f7log: Hermes accepts PR 259 findingmre
- bb0976acrecords: hycon PR 259 design findingmre
- 5c637c24records: hycon PR 259 false tool errormre
- a344c406log: routger 132 reviewedmre
- 56e70dcbrecords: review time limit 1800 s (routger 132)mre