Skip to content

fix(connect): answer plain serve timeout for history reads - #229

Merged
auto-wood merged 1 commit into
mainfrom
fix/history-read-serve-timeout
Nov 26, 2026
Merged

auto-wood merged 1 commit into
mainfrom
fix/history-read-serve-timeout

Conversation

@auto-wood

Copy link
Copy Markdown
Contributor

Summary

A scoped history.revisions.get that outlived the serve budget answered OUTCOME_UNCERTAIN, implying the read might have committed. Reads cannot commit, so they now answer the plain serve timeout, matching the other read paths. history.revisions.prune keeps the uncertain mapping so a same-key replay can recover a settled prune through the recorded-outcome dedup.

Read/write mapping

Op budget expiry after invocation dropped result channel / service throw
history.revisions.get (read) INTERNAL_ERROR, details.kind = "timeout", no retry_class INTERNAL_ERROR (history service failed after invocation: ...), no retry_class
history.revisions.prune (write) OUTCOME_UNCERTAIN, details.kind = "timeout", retry_class = "uncertain" OUTCOME_UNCERTAIN, details.kind = "panic", retry_class = "uncertain"

A zero budget still answers the plain serve timeout before invocation for both ops. Rust and TypeScript keep parity; the wire shapes are unchanged.

Files: crates/spoke-connect/src/remote/responder.rs, crates/spoke-connect/tests/remote_loopback.rs, packages/spoke-connect-ts/src/remote/responder.ts, packages/spoke-connect-ts/tests/remote/history-face.test.ts.

Verification

  • cargo +nightly test -p spoke-connect --features remote-adapter --test remote_loopback gated_scoped_history_admission — 1 passed, 0 failed
  • cargo +nightly test -p spoke-connect --features remote-adapter --test history_conformance — 7 passed, 0 failed
  • pnpm -F @42ch/spoke-connect test — 40 files / 651 tests passed
  • pnpm -F @42ch/spoke-connect typecheck — clean

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Confidence Score: 4/5 · The PR appears safe to merge, with a non-blocking gap in regression tests for service failures.RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The change affects error replies in remote history serving.

The PR appears safe to merge, with a non-blocking gap in regression tests for service failures.

Findings

  1. P2 Read failures lack regression tests ▶
Fix with agent prompt
### Issue 1
packages/spoke-connect-ts/src/remote/responder.ts:2238-2241
The new tests cover budget expiry, but not these separate service-failure branches. The existing Rust admission-panic test catches the panic inside `HistoryPortService`, before the responder sees a dropped result channel.

Add raw `RemoteHistoryService` tests that throw in TypeScript and panic in Rust. Assert `INTERNAL_ERROR` without `retry_class`, and keep a prune case asserting `OUTCOME_UNCERTAIN`. Otherwise, this mapping can regress without either timeout test failing.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

History reads now return plain timeout or internal errors instead of claiming that a write may have committed.

  • History reads time out without suggesting that a write may have happened.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[History request] --> B{Zero serve budget?}
  B -->|Yes| C[Plain timeout; service not called]
  B -->|No| D[Invoke history service]
  D --> E{Budget expires or service fails?}
  E -->|No| F[Return service result]
  E -->|Yes| G{Read or prune?}
  G -->|Read| H[Plain timeout or internal error]
  G -->|Prune| I[Uncertain outcome; same-key replay]
Loading

Reviews (1) · Last reviewed commit: "fix(connect): answer plain serve timeout..." · Reviewed by Greptile

@auto-wood
auto-wood force-pushed the fix/history-read-serve-timeout branch from 9949aa6 to 2cad76b Compare November 26, 2026 00:36
@m-inspector

m-inspector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

✅ Verdict: ship it · Score 98% (mergeable)

Findings Count
🔴 must-fix 0
🟠 should-fix 0
🟡 may-fix 0
🔵 nit 1

📋 Review

What this PR does: This PR splits the history.* serve-budget outcome mapping by operation. history.revisions.get is a read, so an expired budget after invocation now answers the plain serve timeout (INTERNAL_ERROR, details.kind = "timeout") and a thrown/dropped service answers a plain internal error with no retry_class, while history.revisions.prune keeps the OUTCOME_UNCERTAIN/retry_class = "uncertain" mapping so a same-key replay can recover a settled prune through recorded-outcome dedup. Zero-budget refusals before invocation and all success wire shapes are unchanged; the English and Chinese history reference pages and the TypeScript loopback tests are updated to match, and the PR reports matching Rust behavior.

Findings

🔵 Use the exported HISTORY_OP_GET constant instead of a literal op string

  • Evidence:

    • Evidence: packages/spoke-connect-ts/src/remote/responder.ts:2206 — the new read/mutate split classifies the op with the raw literal doc.op === "history.revisions.get"; packages/spoke-connect-ts/src/remote/serve_ports.ts:159 and :203 perform the same op discrimination through the exported HISTORY_OP_GET constant, which is also re-exported at packages/spoke-connect-ts/src/remote/index.ts:52.
    • Impact: The wire op name now lives as an untyped literal in the responder, next to a canonical constant for the same value. A future rename of the exported constant compiles clean here while silently misclassifying the read as a mutating op — flipping read failures back to OUTCOME_UNCERTAIN — with no type error to catch it.
    • Effort: XS
    • Risk: LOW — value-identical replacement; the only addition is the value import from the ./serve_ports.js module this file already re-exports types from.
    • Confidence: HIGH
    • Merge class: nit
    • Fix sketch: Import HISTORY_OP_GET from ./serve_ports.js and compare doc.op === HISTORY_OP_GET. Fix class is mechanical (a lint rule banning raw history.*/memory.* op literals outside the op-table module would cover it); existing checks do not because the literal is type-valid.

    Scope note: within this seat's four-file scope the docs rows (docs/reference/history.md:99-103, docs/zh/reference/history.md:99-103) and the three added TS tests were checked against the implementation and show no further defect; the untested remainder is line-by-line reading of the full 1400-line history-face.test.ts and the full responder.ts outside the touched hunks.

  • Location: packages/spoke-connect-ts/src/remote/responder.ts:2206

  • Category: tech-debt

  • Merge class: nit

Revalidated findings

Reassessed 7/8 prior finding(s) this round · 1 invalid-output · 0 omitted · 0 over cap · 8 recheckable · context coverage: truncated

finding disposition evidence thread
Panicking history double is documented as post-admission/post-commit, but panics at entry addressed (verified-fix) current-code -
Update the published history refusal vocabulary for read ops unverifiable (invalid-output) - -
Inline serve-bound note above uncertainOnExpiry still states every post-invocation history expiry is OUTCOME_UNCERTAIN addressed (verified-fix) current-code -
New history.revisions.get INTERNAL_ERROR row claims details are always absent, but the reachable transport-kind path carries { kind: "transport" } addressed (verified-fix) current-code -
[DEBT] New responder↔serve_ports runtime import cycle introduced by the HISTORY_OP_GET value import unverifiable (context-incomplete) - -
Read-path split leaves the history uncertainty contract documented as prune-wide addressed (verified-fix) current-code -
Refusal vocabulary claims unrecognized history.* ops reach invocation, but the responder rejects them at the gate addressed (verified-fix) current-code -
Mirror Rust's is_read predicate instead of an inverted is_prune default addressed (verified-fix) current-code -

Linked-issue AC

none — the captured PR context links no issue (issues: []), so there are no acceptance criteria to score.

✅ Verified

- packages/spoke-connect-ts/src/remote/responder.ts:2206 — the new isRead split gates both the uncertainOnExpiry argument and the post-invocation throw path, so reads answer plain INTERNAL_ERROR while prune alone keeps OUTCOME_UNCERTAIN with retry_class: "uncertain" and kind: "timeout"|"panic".
- packages/spoke-connect-ts/src/remote/responder.ts:2158-2171 — the serve-bound note above #dispatchHistoryInvoke now matches the split: zero budget refuses pre-invocation, reads are plain, only prune stays uncertain and recoverable through dedup.
- docs/reference/history.md:99-103 and docs/zh/reference/history.md:99-103 — both refusal tables state the read paths (zero-budget refusal, plain timeout, thrown service with absent details, malformed/wrong-target snapshot with { kind: "transport" }) and the prune-only OUTCOME_UNCERTAIN row consistently with the implementation, including the same-key replay rationale.
- packages/spoke-connect-ts/tests/remote/history-face.test.ts:1233,1272,1307,1342 — the added loopback tests assert exact read-timeout details { kind: "timeout" }, a read throw with no details and the exact history service failed after invocation: ... message, prune throw → { retry_class: "uncertain", kind: "panic" }, and prune expiry → OUTCOME_UNCERTAIN followed by a same-key replay that succeeds with exactly one port call.
- Prior-finding revalidation: six findings are addressed as verified fixes (panic-double documented at post-admission/post-commit, inline serve-bound note, { kind: "transport" } details row, prune-wide uncertainty contract wording, refusal-vocabulary gate claim, is_read-style predicate mirroring).
- packages/spoke-connect-ts/src/remote/serve_ports.ts:66 and packages/spoke-connect-ts/src/remote/index.ts:52 — HISTORY_OP_GET is exported and re-exported, confirming the canonical constant the nit points at exists.
- ❓ The responder.ts ↔ serve_ports.ts runtime import cycle flagged in the revalidation table is still open in that table (context-incomplete); reading shows serve_ports.ts:40-45 value-imports isJsonObject/validators from ./responder.js while responder.ts:124 currently imports only types from serve_ports.js, so the nit's direct value import would close the cycle.
- ❓ Rust parity (crates/spoke-connect/...) is outside this seat's four-file scope; only the PR body's claim and its own cited cargo runs cover it.
- ❓ Remaining line-by-line reading of the full ~1400-line history-face.test.ts and the full responder.ts outside the touched hunks was not performed in this seat.
- ❓ Author-reported verifications (pnpm -F @42ch/spoke-connect test 40 files / 651 tests, typecheck clean, cargo +nightly ... gated_scoped_history_admission, history_conformance) were not re-run in this read-only review.

🗑️ Considered & rejected

- Uniform uncertainty for both ops was rejected: a read cannot commit, so OUTCOME_UNCERTAIN would invite a pointless same-key replay and contradict the other read paths the mapping now matches.
- Dropping retry_class on read failures was not treated as a broken retry contract: there is no effect to retry, the tests assert its absence exactly, and prune retains the uncertain class.
- Changing the zero-budget pre-invocation refusal per op was rejected: both ops refuse before the service is invoked, so the plain timeout is correct and left unchanged.
- Keeping the read INTERNAL_ERROR row as "details always absent" was rejected: the reachable malformed/wrong-target snapshot path legitimately carries { kind: "transport" }, and both doc rows now name it.
- Treating a thrown read service as OUTCOME_UNCERTAIN because the throw may follow port entry was rejected: the read has no commit to be uncertain about; plain INTERNAL_ERROR with no details is the tested behavior.
- No additional defect was found in the English/Chinese docs rows or in the added TypeScript tests within this seat's scope; no success-shape or wire-format regression was identified.

🛠️ Plan to fix

Expand fix plan
The single surviving finding is a nit, so this plan is optional and may land separately; the PR is mergeable as-is.

1. **Locate the constant safely** — `packages/spoke-connect-ts/src/remote/serve_ports.ts:66` exports `HISTORY_OP_GET`, but that module value-imports `isJsonObject`/`validateAdoptRejectReceipt`/`validateDeclaredScope` from `./responder.js` (`serve_ports.ts:40-45`), while `responder.ts:124` imports only types back from `./serve_ports.js`. A direct value import in `responder.ts` would close a `responder → serve_ports → responder` ESM cycle. Preferred: hoist `HISTORY_OP_GET`/`HISTORY_OP_PRUNE` into a leaf module (for example a new `history_ops.ts`, or the existing `payload.ts` if that stays import-leaf) that imports neither `responder.ts` nor `serve_ports.ts`, then re-export both names from `serve_ports.ts` and `index.ts` so the public surface is unchanged. Fallback: import `HISTORY_OP_GET` from `./serve_ports.js` only after confirming the cycle is evaluation-safe under the project's Node/bundler targets.

2. **Replace the literal** — in `packages/spoke-connect-ts/src/remote/responder.ts:2206`, change `const isRead = doc.op === "history.revisions.get";` to `const isRead = doc.op === HISTORY_OP_GET;` and add the value import alongside the existing type re-export (`responder.ts:124`, and the re-export block ending at `responder.ts:882`). Keep the comparison value-identical; do not touch the throw-path or `uncertainOnExpiry` logic.

3. **Optional hardening** — add a lint rule banning raw `history.*`/`memory.*` op literals outside the op-table module, since the existing type checks accept the literal and cannot catch a future constant rename.

4. **Verification gates** — `pnpm -F @42ch/spoke-connect typecheck` (must stay clean with the added value import); the package's test run with the `history-face` suite, checking that the four read/prune assertions at `tests/remote/history-face.test.ts:1233,1272,1307,1342` still pass with unchanged exact `details` equality; and one import-graph check (build/bundle or a small cycle assertion) proving `responder.ts` and `serve_ports.ts` have no new runtime cycle. No Rust or docs changes are needed for this nit.

5. **Files touched** — `packages/spoke-connect-ts/src/remote/responder.ts` (required); `packages/spoke-connect-ts/src/remote/serve_ports.ts` and `packages/spoke-connect-ts/src/remote/index.ts` only if the constants are hoisted; no test, doc, or Rust edits.

Review 6 · commit eb85069

@m-inspector m-inspector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mstar-inspector line comments · round 1 · 9949aa6

@m-inspector m-inspector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mstar-inspector line comments · round 2 · 2cad76b

@auto-wood
auto-wood force-pushed the fix/history-read-serve-timeout branch 3 times, most recently from 884d0f8 to 8e6cb0b Compare November 26, 2026 01:10

@m-inspector m-inspector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mstar-inspector line comments · round 3 · 0b113db

Comment thread docs/reference/history.md Resolved

@m-inspector m-inspector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mstar-inspector line comments · round 4 · 8e6cb0b

Comment thread docs/reference/history.md Resolved
@auto-wood
auto-wood force-pushed the fix/history-read-serve-timeout branch from 8e6cb0b to 8db1001 Compare November 26, 2026 01:40

@m-inspector m-inspector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mstar-inspector line comments · round 5 · 8db1001

- history.revisions.get answers the plain INTERNAL_ERROR serve timeout
  (details.kind = timeout, no retry_class) on budget expiry, and a plain
  internal error when the detached invoke drops its result channel.
- Every other history op (prune and unknown ops) keeps
  OUTCOME_UNCERTAIN/uncertain for both post-invocation failures,
  recoverable through the recorded-outcome dedup.
- Zero-budget rejection is unchanged for both ops; Rust and TS stay in parity.
@auto-wood
auto-wood force-pushed the fix/history-read-serve-timeout branch from 8db1001 to eb85069 Compare November 26, 2026 02:09

@m-inspector m-inspector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mstar-inspector line comments · round 6 · eb85069

@auto-wood
auto-wood merged commit 06e1f68 into main Nov 26, 2026
34 checks passed
@auto-wood
auto-wood deleted the fix/history-read-serve-timeout branch November 26, 2026 02:38
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.

2 participants