gitoria

tickets

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commit467d7286467d7286Tickets conductor: T36 done, deploy questionmre467d7286/plugins/fetch/pending_fetch.hl

4.0 KB

  1. \* A request in flight. Handed back by fetch()/fetchStart() — never `new`ed.
  2. The request is already on the wire when you hold one: it has a thread of
  3. its own, holding one costs a socket, not a fiber. With stream = true the
  4. events below arrive AT this object. *\
  5. \* A decoded piece of the body, token by token (stream mode). *\
  6. emit chunk(
  7. String chunk \\ the decoded bytes as they arrived
  8. )
  9. \* The stream's final frame — body is EMPTY, the chunks were the body. *\
  10. emit done(
  11. Number status \\ the HTTP status
  12. Boolean ok \\ true for 2xx
  13. Hybrid headers \\ response headers
  14. String error \\ '' or the failure text
  15. Boolean aborted \\ true when abort() cut it
  16. )
  17. Hybrid #handle
  18. Number #srcId = 0
  19. // Has the answer arrived? Never waits — a poll for code that wants to do
  20. // something else in the meantime.
  21. done() {
  22. return #handle.done()
  23. }
  24. // THE WAIT. Blocks the calling fiber until the answer is in, then hands back a
  25. // FetchResponse. A failed fetch (refused connection, timeout, TLS verification,
  26. // too many redirects) surfaces here as a located error routed to `on Error`, so
  27. // a caller that wants to survive one writes an `on Error(e)` handler.
  28. response() {
  29. // Not in yet: let the sibling fibers (a `concurrent` group, the loop's other
  30. // handlers) run instead of blocking the thread on this socket. On the process
  31. // stack there is no one to yield to and result() is the wait.
  32. // The yield names the fetch's bell (an eventfd rung when it is done): a
  33. // `concurrent` group whose arms ALL wait sleeps on those, not on a timer.
  34. let bell = #handle.doneFd()
  35. while (!#handle.done()) {
  36. if (!__native("fiber.yield", bell)) { break }
  37. }
  38. let r = #handle.result()
  39. // An `on Error` handler that ABSORBED the failure leaves the call yielding
  40. // null (the plugin-error contract every `hl:` module follows). Hydrating null
  41. // would be a second, misleading error, so a caught failure answers null —
  42. // exactly what `hl:fs`'s file() does.
  43. if (r == null) {
  44. return null
  45. }
  46. return r > new FetchResponse()
  47. }
  48. // STREAM MODE (the LLM-token flow). `fetch(url, { stream = true })` calls this
  49. // before handing the instance out: the ticket's own event source is registered
  50. // AT this instance and the fan-out below re-emits every frame at itself, so app
  51. // code holds nothing but the object and its events — `on p.chunk`, `on p.done`.
  52. arm() {
  53. #srcId = __native("eventloop.register", #handle.events(), "__fetchEvent")
  54. }
  55. // THE FAN-OUT: a native frame in, a DECLARED event out. The frames are Hybrids
  56. // ({ tag, url, chunk } or { tag, url, status, ok, body, error, headers, aborted });
  57. // `chunk` and `done` above declare TYPED parameters, so each field is handed over
  58. // BY NAME — `emit chunk(ev)` would bind a Hybrid to `String chunk` and fail every
  59. // frame (mission 257: it did).
  60. //
  61. // NAMED, NOT POSITIONAL, and that distinction cost the creator a night (2026-08-30).
  62. // 257 fixed the Hybrid-into-String bind by emitting POSITIONALLY — `emit
  63. // chunk(ev.chunk)` — which type-checks and is still wrong: every handler in this
  64. // language receives a PAYLOAD OBJECT and destructures it. His own working code is
  65. // `on stream.chunk({ chunk })`, exactly as `on server.line({ line, stream })` reads
  66. // for hl:proc and as his `emit ready(port = …)` writes it. Positional emission
  67. // hands `{ chunk }` a String, and the app dies with "Cannot destructure non-object
  68. // value" — a DIFFERENT error from the one 257 fixed, on the same line of his app.
  69. // `name = value` is the form that satisfies the typed declaration AND keeps
  70. // destructuring working. Do not "simplify" it back.
  71. on __fetchEvent(ev) {
  72. if (ev.chunk != null) {
  73. emit chunk(chunk = ev.chunk)
  74. return null
  75. }
  76. // the final frame — retire the source so the loop can end by itself
  77. __native("eventloop.unregister", #srcId)
  78. emit done(status = ev.status, ok = ev.ok, headers = ev.headers, error = ev.error, aborted = ev.aborted)
  79. return null
  80. }
  81. \* THE STOP BUTTON: abort this fetch — the socket is shut down, the peer
  82. sees the disconnect and stops generating, and `done` arrives with
  83. aborted = true. (fetchAbort(tag) cuts a whole tag at once.) *\
  84. abort() {
  85. return #handle.abort()
  86. }

Branches

Latest commits

  • 467d7286Tickets conductor: T36 done, deploy questionmre
  • 8542fc8aTickets conductor: T36 proof reviewedmre
  • 2a5b8b91Tickets conductor: T36 cap stop, resumed for proofmre
  • 6a82097fTickets conductor: Arachne W228 on day35 flakemre
  • 0ee5a6f2Tickets conductor: T36 resumedmre
  • 9149c165Tickets conductor: T36 diagnosismre
  • 91713313Tickets conductor: T36 report 1mre
  • 756315d2Tickets conductor: T36 startedmre
  • 0814ce6bTickets conductor: brief 025 tickets#36 style formmre
  • 1b6916c4Tickets conductor: Atlas handover tickets#36mre
  • aab95226Tickets conductor: worldapi-conductor paths, deploy blocker = read-only diskmre
  • 6372b06dTickets conductor: worker port slotmre
  • 836af31cTickets conductor: token pathsmre
  • b03f11b6Tickets conductor: CONDUCTOR.md (project part), short STATUS.md, old STATUS to archive/2026-10-31mre
  • a4123831tickets#42: the /connect and /login/callback error pages are app pages: the function routes redirect to /connect/failed/<code> and /login/failed/<code> (components/problem.hl, sentences in lib/problems.hl), htmlPage and its hand-written stylesheet are gone; gate tests/error-pages.mjsmre
  • cefc7b4atickets: a startup error prints its message before exit 1 (hybriel#247)mre
  • 99bd6570tickets: lib/migrate.hl writes no table of another topic any more: projects.hl rewriteSlug / addProjectNamed / hasMembers, tickets.hl moveToProject / ticketRecords / ticketRecordsOf, events.hl renameStates / eventRecords / eventRecordsOf; the migration calls them (tickets#47)mre
  • b57161e3tickets: the markup names its own rules (Style.pMessage, Style.olTickets, ...) instead of hand-written class strings that copy a stylesheet rule; the shared bodies sit in lib/looks.hl (tickets#38)mre
  • f767b24dtickets: 111 needless let became plain declarations (3 in ticket.hl, ticket_list.hl, comments.hl and 108 never-reassigned, not captured loop-body ones); the 212 really reassigned lets stay (tickets#44)mre
  • 16c0d3b5tickets: the modal window is phone first: the full-screen sheet is the base rule, the centred window sits in the min-width 60rem block (tickets#39)mre