Skip to content

fix(control): keep a taken message open past expires_at so its final ack lands - #280

Open
connorburgess wants to merge 3 commits into
spacesheep-dev:mainfrom
connorburgess:fix/control-taken-not-expired
Open

connorburgess wants to merge 3 commits into
spacesheep-dev:mainfrom
connorburgess:fix/control-taken-not-expired

Conversation

@connorburgess

@connorburgess connorburgess commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Updated against v0.8.18 / main d16a2c01 on 2026-12-05. Current validation and refresh details.

What

A message the machine has acked taken is no longer marked expired by the receiver when its expires_at passes while the machine is still delivering it. The machine's final ack (for example delivered with its reply) is now applied instead of being dropped. If the machine acks taken and then never sends a final ack, the row is closed unconfirmed once the 35-minute taken pause is over. It is no longer closed expired with the detail "expired before the machine took it".

Why

expireQueue (server/control/state.ts) skipped only rows whose outcome was already final. taken is not final. CONTROL.md §10 says: "Not final. The machine verified the message and is delivering it; a final ack follows", and "Every message is acked exactly once with a final outcome, optionally preceded by taken". So a row acked taken that ran past expires_at (default 1 h) was overwritten as expired, with a detail meant for rows the machine never took. When the machine's final ack came in, ack() skipped it because the row was already final, while the response still said 202 {applied: 1}. The reply was lost and the activity showed the message as never taken.

The fix is limited to expireQueue:

  • A row with takenAt stays open while it is inside the taken pause (TAKEN_PAUSE_MS, 35 minutes from takenAt). This is the window that already pauses redelivery in deliverable().
  • The row is never held open longer than the pause past expires_at. takenAt is the machine's own clock, so a clock running far ahead cannot keep a row open indefinitely.
  • After the pause it is closed unconfirmed with no code. This is the outcome remote.ts already uses for a job that was taken and never heard of again, and the page already words it ("No word from X since it took this"). expired would claim the machine never took it.
  • Untaken rows and remote rows behave exactly as before.

Two small follow-ons, because a taken row can now be open past expires_at:

  • web/src/control/usePoolSend.ts: onItsWay counts a taken row as on its way. Without this, the pool note would go blank between expires_at and the final ack.
  • server/orchestrate/index.ts: a comment that described the old expiry of taken rows now says when that expiry happens.

Left as they are, on purpose:

  • Rows that older releases already saved as expired after taken stay expired. A late final ack for one of them is still dropped, as before. Reopening receiver-expired rows would need a way to tell them apart from a machine's own expired ack, and the case only covers messages that were in flight during the upgrade.
  • progress acks do not extend the pause. The 35-minute bound comes from §10.
  • A machine whose clock runs more than 35 minutes slow gets no extra time. deliverable() reads takenAt the same way today.
  • Files attached to a message are still kept only until expires_at (files.keepUntil in enqueue). This was already the case before this change.
  • key.add rows still settle through keyAddSettled when they close. A taken key.add that never gets a final ack now settles the device request as failed with outcome unconfirmed, not expired.

Shared file: #276 (fix/config-utf16-bom) also changes server/control/state.ts, in its writeAtomic and machines-loading code near the top of the file. This change only touches expireQueue. git merge-tree --write-tree of this branch against #276's head (42e7a90) and against origin/main (6165bed) both finish without conflicts.

Original proof (before the v0.8.18 refresh)

New test in server/control/control.test.ts, "a message the machine has taken is not expired at expires_at; its final ack is kept". It sends a prompt with expires_in_s: 60, the machine polls it and acks taken, the clock moves 2 minutes forward, and the machine acks delivered with a reply. The test also covers a taken row whose machine goes silent (closed unconfirmed after the pause) and a taken ack stamped 24 h in the future (closed unconfirmed once the pause past expires_at is over).

On origin/main's server/control/state.ts (with the new test), it fails:

 FAIL  server/control/control.test.ts > the queue > a message the machine has taken is not expired at expires_at; its final ack is kept
AssertionError: expected { …(12) } to match object { outcome: 'taken' }
(11 matching properties omitted from actual)

- Expected
+ Received

  {
-   "outcome": "taken",
+   "outcome": "expired",
  }

 Test Files  1 failed (1)
      Tests  1 failed | 402 skipped (403)

On this branch:

 Test Files  1 passed (1)
      Tests  1 passed | 402 skipped (403)

npx vitest run server/control server/orchestrate web/src/control:

 Test Files  32 passed (32)
      Tests  840 passed (840)

npm run typecheck: passes, with no output from either tsc run.

npm run lint:

Checked 983 files in 173ms. No fixes applied.
Found 135 warnings.
Found 1 info.

The warnings and the info (biome.json's schema 2.6.8 against CLI 2.6.9) are in files this change does not touch.

npm test:

 Test Files  248 passed (248)
      Tests  3368 passed | 2 skipped (3370)

An earlier full run on the first version of this commit had server/control/remote.parity.test.ts time out at its 15 s limit. That file passed in every targeted run, and it passes in this full run.

An entry is now included under Unreleased in CHANGELOG.md. Other open PRs also add release notes; those entries may need combining as the PRs land.

Checklist

  • Every commit is signed off (git commit -s): the DCO is the only paperwork.
  • npm run typecheck && npm run lint && npm test pass; npm run test:e2e for a UI change. npm run test:e2e was not run: the only UI change is one condition in usePoolSend.ts.
  • New source files start with // SPDX-License-Identifier: Apache-2.0. (No new files.)
  • No secret, real address, hostname or home path in code, fixtures or screenshots (screenshots come from --demo).
  • A change to shared/* names the wire-contract change in the description. (No shared/* change.)
  • A line under Unreleased in CHANGELOG.md.

…ack lands

Symptom: a message the machine acked `taken` and was still delivering
was marked `expired` ("expired before the machine took it") once its
expires_at passed. The machine's final ack (e.g. `delivered` with its
reply) was then answered 202 but dropped, so the reply was lost.

Cause: expireQueue skipped only rows whose outcome was final. `taken` is
not final (CONTROL.md §10: the machine is delivering it and a final ack
follows), so the receiver overwrote it, and ack() ignores acks for rows
that are already final.

Fix: expireQueue leaves a taken row open for the taken pause
(TAKEN_PAUSE_MS, 35 minutes from takenAt, the window that already pauses
redelivery), and never longer than that past expires_at, since takenAt
is the machine's clock. A taken row with no final word by then is closed
`unconfirmed`, as remote.ts closes a job taken and never heard of again,
not `expired`, which says the machine never took it. The pool send note
counts a taken row as on its way past expires_at, and the orchestrate
comment that relied on the old expiry says when it now happens.

Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
Signed-off-by: Connor Burgess <connorburgesscodes@gmail.com>
@connorburgess

Copy link
Copy Markdown
Contributor Author

The taken-message expiry and final acknowledgement fix still applies to SessionPipe GUI v0.8.18. Merged current main (d16a2c01) into this branch; the refreshed head is c1728318. The affected files have not changed upstream, and the original change is preserved.

Added the previously deferred Unreleased changelog entry.

Validation on this head, macOS / Node 22.23.2:

  • npm run typecheck, npm run lint, and npm run build passed. Lint has the same 135 warnings and one informational diagnostic as current main, with no errors.
  • npx vitest run --maxWorkers=2 server/control server/orchestrate web/src/control: 840 tests passed.

GitHub CI run 47453783115 for head c1728318 passed: typecheck · lint · unit · build, all three desktop e2e shards, e2e (phone · duo), e2e (control channel), and the aggregate typecheck · lint · unit · build · e2e gate.

Also checked the combined source/test changes from all 19 refreshed PRs on the same main: no source conflicts; typecheck, lint and build passed; all 252 unit-test files passed (3,439 tests, two skipped). This was a local integration check, separate from the individual PR run above. Release-note entries may still need combining as PRs land.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant