gitoria

gitoria

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Main branchmainfe209ffeMerge branch 'w56-owner-members' into mainGitoriamain/reports/W43-REPORT.md

9.6 KB

  1. # W43 — signed events to connected apps (gitoria#43)
  2. Branch `w43-events` in `/media/STORAGE/claude-scratch/gitoria/W43/wt`, based on main 1997e77 and merged with main 5a996ea (#42) as asked. Last commit cd44206. Not pushed, not deployed, no tickets written.
  3. ## What was built
  4. - `lib/events.hl`, `lib/events-helpers.hl` (new): `raiseEvent(repo, event, action, extra, senderId)`, `raisePing`, `syncAndRaise(slug, userId)`, `sendDue()`, `redeliver(appId, deliveryId)`, `deliveryPage(appId, cursor, limit)`.
  5. - `deliveries.db`: {id (uuid), app, repo, event, action, body, tries, step, nextAt, status pending|delivered|failed, lastCode, created, updated, claimedBy, claimedUntil}.
  6. - `tries` counts attempts and is never reset. `step` is the position in the retry schedule.
  7. - `body` is built once at raise time and stored as the exact bytes that are signed and sent, so a retry or redelivery sends the same bytes and the same uuid.
  8. - `lib/apps-table.hl` (new): `appsTable`, `appsOfRepo` and `appWith` moved out of `lib/apps.hl`. `lib/events.hl` needs to read the apps while `apps.hl` raises the ping, and a circular import was the alternative. Behaviour is unchanged. `lib/app-auth.hl` now imports from the new file.
  9. - Wiring:
  10. - `syncAndRaise` replaces `syncPulls` in the three places a push or merge lands: `lib/transport.hl` (HTTPS push), `lib/api.hl` gitPushed `after` (ssh push), and the Merge button in `components/pulls.hl`.
  11. - It raises `pull_request` opened / reopened / synchronize{before, after, forced} / closed / merged{mergeCommit}, with `pull` = `pullObject`.
  12. - `pingAfterConnect` raises the ping for both ways A and B.
  13. - Settings → Apps has a "Send ping" button per app (`sendPing` in apps.hl, face `gitoriaAppPing`, owner only).
  14. - Sender: `sender = every(tickSeconds())` and `on sender.tick() { sendDue() }` in `project.hl`.
  15. - Headers, HMAC and `fetch` are as the brief says: `hkdfExtract(toBytes(secret), toBytes(body)).hex()` is the HMAC, timeout 10 s, `maxRedirects` 0, 2xx = delivered.
  16. - Retry waits are 1 min, 5 min, 30 min, 2 h, 6 h, then `failed`. `urlAllowed` is checked again at send time.
  17. - The app's `lastDelivery` / `lastStatus` are updated, e.g. "pull_request delivered (204)". `lastStatus` is not live-updated on the open Settings page: it shows after a reload.
  18. - Routes from #42's helpers: `GET {api}/deliveries?cursor=&limit=` and `POST {api}/deliveries/:id/redeliver` (`appDeliveries`, `appRedeliver` in `lib/api.hl`; `apiPatterns` for all three address forms).
  19. - An app sees only its own rows. Another app's id gives 404. The cursor is "created_id" of the last row, so rows raised meanwhile do not shift the next page.
  20. - Test-only env: `GITORIA_EVENTS_TICK` and `GITORIA_EVENTS_RETRY_MS`. README has a section; `tests/events.mjs` is in GATES in deploy.sh.
  21. ## Claim: why only ONE process sends a row
  22. The table has no compare-and-set, and an mpackdb handle does not see another process's writes (README "Another process's appends and deletes are not seen"). So the claim is the file system's: `mkdir storage/claims/<delivery>.<tries+1>` via `run(['mkdir', …])`. A POSIX mkdir without `-p` fails atomically when the folder exists, across processes.
  23. - Only the process whose mkdir succeeds sends that attempt. The next attempt has a new number, so old folders never block later ones.
  24. - `claimedBy` / `claimedUntil` and `tries` are written to the row BEFORE the POST. The other process skips a row whose `claimedUntil` is in the future. The gate found this gap: a second process claimed attempt number 2 under an in-flight attempt 1, and the receiver got a duplicate. It is fixed and the two-process check is green.
  25. - A claimed attempt whose process died (`claimedUntil` + 30 s passed, row unchanged) is closed by a second folder `<delivery>.<n>.dead` (again one winner) and counted as failed.
  26. - Retention (every minute, in the sender): rows older than 7 days go, then at most 200 per app (oldest first). Claim folders of deleted rows are removed.
  27. ## Tests
  28. `LC_ALL=C node tests/events.mjs`: **48 passed, 0 failed**, green in the last 2 runs (the earlier runs found the real bugs above). Checks:
  29. - Signature: RFC 4231 case 2 gives `5bdcc146…3843`. Cross-check against `openssl dgst -sha256 -hmac` with a 64-hex key and a UTF-8 body matches. Delivery id is a uuid v4.
  30. - Events and headers: ping at connect (way B) only to the app of that repo, with headers, signature verified by the receiver, and the common body. opened (umlaut title, tickets, pull object, `refs/pull/1/head` = `pull.head` at delivery), synchronize not forced, synchronize force-push (`forced` true, before/after), merged by the Merge button (face `gitoriaMergePull` as the logged-in owner, `mergeCommit` = new tip of main, sender), closed by deleting the branch, "Send ping" button (non-owner and signed-out refused), no delivery to the other repo's app.
  31. - Retries and failure: receiver cutting the connection twice gives 3 tries with the same delivery id and the same bytes, waits of at least 1.3 s. Answering 500 gives 4 tries and then `failed (500)` in Settings. A 302 is a failure and is not followed.
  32. - Speed: PR pushes with a hanging receiver (open and synchronize) stay within base + 4 s, and `/api/repos` answers while a delivery hangs.
  33. - Two gitoria processes on one storage: 6 events give 6 deliveries, none twice, and claim folders exist.
  34. - `/deliveries` paging, `/deliveries/:id/redeliver` (same uuid and same bytes, log shows delivered afterwards), and 401 / 404 / 405 cases.
  35. - Retention: old rows gone, exactly 200 kept per app.
  36. Other gates (LC_ALL=C), all 0 failed:
  37. - `check-theme` 69 files, 0 problems
  38. - `signin-return` 3
  39. - `security` 82
  40. - `private` 158
  41. - `ident-access-gitoria` 30
  42. - `apps` 95
  43. - `pull-numbers` 48
  44. - `pull-ssh` 20
  45. - `app-token` 42, after fixing `tests/app-auth-unit.hl`'s import of `appsTable`
  46. - `events` 48
  47. - `browser` 266, run on ports 8729 / 8728 / 8727 with Chrome ports 8720-8726 (`GITORIA_GATE_*` env).
  48. - The default port 8700 was held by another process (pid 3917192), and 8722 is held by someone throughout.
  49. - With only 5 Chrome ports (8725-8729) the gate crashed twice with "no bindable port" after 184 and 220 passes. That is port scarcity of this slot, not a code failure. It needs ≥6 usable Chrome ports.
  50. ## Contract points
  51. Covered: §4 headers and signature, delivery rules, retries, no redirects, common body, pull_request events, ping at connect and via the button, `GET /deliveries`, `POST /redeliver`.
  52. Not covered:
  53. - `exceptApp` (no event for the app's own action) is implemented in `raiseEvent` but has no gate check, because no caller exists until #44/#45.
  54. - `review_*`, `pull_comment` and `ready` events are for #44/#45.
  55. ## DOCS/GAP
  56. - hl:fs has no exclusive create or compare-and-set, and mpackdb has no cross-process visibility. Worked around with the OS `mkdir` through `hl:proc` `run`, no JavaScript. A doc line on cross-process claims would help.
  57. - `listDir` returns an iterator of {name, path, type…} (not an array of names). Its signature is undocumented in the README table.
  58. - Hybriel: two imports of the same name from different modules clash in the browser build: "'withChange' is already imported" (I renamed mine to `appWith`). Repro: import `withChange` from `repos-helpers.hl` and from another file in one component tree.
  59. - A fetch that fails is absorbed by `on Error` in project.hl and logged as "error absorbed: hl:fetch POST …" in the server log. That is the documented behaviour, but it is noisy for normal retries.
  60. ## Open risks
  61. - Stale cross-process records: `appWith` (lastDelivery / lastStatus) re-reads the app row just before the write, but another process's `update()` of the same app (rotate or re-connect) in that instant could be overwritten by a stale copy. The window is small, and the standby only serves during a deploy.
  62. - The sender is one serial timer: a hanging receiver holds the ticks for up to 10 s, so deliveries to other apps wait behind it. Pushes and pages are not affected (tested). Fix later: a worker per app.
  63. - Browser proof of the new "Send ping" button in his Chrome on lisbeth :9223 (the rule for UI changes) was NOT done: no tunnel / lisbeth Chrome from this worker. The gate covers the button in the served HTML, the face, and the delivery. A single quiet button next to the existing ones, no layout change. **Needs a look in his Chrome at 390 / 800 / 1280.** No tab of mine was opened anywhere.
  64. - The ssh path (`/__git/pushed after` → `syncAndRaise`) is covered by `pull-ssh.mjs` (green) but not by an event check over ssh.
  65. ## Processes
  66. Everything I started was stopped by the gates themselves (my last check found nothing of mine listening on 8720-8729; 8722 is someone else's). Test storage stays under `wt/.scratch/` (ignored by git).
  67. ## Addendum (review fix): the sender never writes the apps row
  68. - `noteOnApp` and the `appsTable.update` in `lib/events.hl` are gone, so the sender only writes `deliveries.db`. `appWith` is no longer imported there.
  69. - `events.hl lastDeliveryOf(appId)` returns the newest delivery (by `updated`) as text and time. `apps.hl statusText` uses it for Settings → Apps. The `lastDelivery` / `lastStatus` fields of the apps row are now unused and are never written by the sender.
  70. - Settings now shows a freshly connected app's ping as "ping is waiting" or "will be tried again" instead of "no delivery yet". I changed one assertion in `tests/apps.mjs` (line 165) accordingly.
  71. - `tests/events.mjs` has new checks: rotate the secret, send two deliveries, and the receiver verifies both with the NEW secret (and not the old one). Settings still shows "ping delivered (204)" and no secret.
  72. - Rerun with LC_ALL=C: events 52/0, apps 95/0, security 82/0, app-token 42/0, check-theme 0 problems. Not rerun after this change: browser, private, signin-return, ident-access-gitoria, pull-numbers, pull-ssh (none touch events or the apps status text).

Branches

Latest commits

  • fe209ffeMerge branch 'w56-owner-members' into mainGitoria
  • fa0754c8|||PR repository owner transfer and members API (#55)mre
  • 8862e537Merge branch 'w55-rename-org' into mainGitoria
  • 014d2b7fOne immutable readers snapshot per move for the left-organization event (#53)mre
  • 1859d506Decide who hears a repo left its organization by its readers before the move (#53)mre
  • 499f25f2Review fixes for the Settings organization move (#53)mre
  • ed3b922b|||PR move a repository into an organization in Settings (#53)mre
  • 74ec2af8Merge branch 'w54-repo-rename-pr' into mainGitoria
  • 9f7ce8d8Preserve rename compatibility and live page titlesmre
  • c3d95b6e|||PR separate names and addresses, rename repositories in Settings (#53)mre
  • ce08920dMerge branch 'w52c-header-phone' into mainGitoria
  • 0bab9e46|||PR header: ident status wraps on phones instead of clippingmre
  • e7af3eceMerge branch 'w52b-approval-followup' into mainGitoria
  • c01e66c6|||PR approvals follow-up: live Merge after status writes, helpers (#52)mre
  • 841da497Merge branch 'w53-pulls-speed-pr' into mainGitoria
  • 80307ae2|||PR pulls page cache: live PR numbers, complete scans onlymre
  • 69141f65|||PR pulls page: cache the git part per repo by branch tipsmre
  • 155861f6Merge branch 'w52-person-approval' into mainGitoria
  • b5435de8|||PR person approvals: second Kunibert round (#52)mre
  • 3a8b2fb8|||PR person approvals: Kunibert review fixes (#52)mre