Skip to content

FIX-2162 (A: server + engine): interrupted read, status sessionId, createInProcessFetch - #3857

Merged
jhoffner merged 7 commits into
mainfrom
fix/fix-2162-a
Oct 24, 2026
Merged

jhoffner merged 7 commits into
mainfrom
fix/fix-2162-a

Conversation

@jhoffner

@jhoffner jhoffner commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

The problem

A caller that saved only a request id cannot continue that request after a crash. The continue and retry routes need the session, and the status read does not give it. The interrupted list from check-interrupted shows only what that one call swept, so a request that a sweep marked first is lost to the caller. Also, a caller who runs FSD in their own process must start a web server to call it.

What this does

This is slice A of FIX-2162: the server and engine side. It adds things only. No client or caller changes; slice B does those, stacked on this PR.

Today: six ways to build a client. After: one createClient with one fetcher, which is a URL over HTTP or createInProcessFetch with no web server

This PR builds the server parts of this figure: the fetcher on the right side (createInProcessFetch) and the reads that a request object needs. The client in the figure is slice B.

  • Request status now returns sessionId. It also applies callerReachesRequest, the tenant and owner check that the abort and recovery routes already apply. Another tenant's request now returns 404.
  • New read: GET /api/flows/users/:userId/interrupted-requests lists the user's interrupted request records on each call. It does not sweep. It uses the same row rule as /active-requests (tenant, then the instance's own resolver, else user and organization).
  • flowId is on both interrupted lists. An old record without it uses flowKind (BP-030). /active-requests does not change.
  • createInProcessFetch(app, { basePath? }) in @flow-state-dev/engine returns a fetch function that calls the engine in this process. @flow-state-dev/node's createServerApp now sends its API requests through it. Now there is one dispatch path.

What's asked of you

Nothing here is yours to decide. This implements the approved direction, and no new product decision came up.

Parts worth reviewing closely

From here, this is for the code reviewer.

  1. The status tenant check (packages/engine/src/routes/request-status-routes.ts). Before, any caller who passed the route guard could read any tenant's request status. Now a caller in another tenant gets 404. A caller that reads status without the tenant header that it used to send will now get 404. I did not find such a caller, but I am not fully sure.
  2. Parity of node with the old dispatch (packages/engine/src/routes/in-process-fetch.ts, packages/node/src/app.ts). Two differences from the old node code: (a) a Request with no init goes through unchanged, and a new Request is made only when init is given; (b) a path outside basePath returns 404. In node, Hono mounts at basePath, so (b) does not change node behavior. Node's 70 tests did not change and pass.
  3. The shared row rule (listingAdmits in recovery-routes.ts). I moved the /active-requests rule into one function. The new read uses it too. The order of checks did not change.

Fixes FIX-2162 (slice A of 2) · spec specs/issues/FIX-2162/ · spec review #3810 · goal check goals/client/does-every-job-with-one-client/ needs the client, so it runs in slice B · slice B stacks on this PR

How to review this

How to review this. This implements an approved spec — the approach and the numbered
decisions in its DECISIONS.md are already signed off by a human, so please review the
code against that direction, not the direction itself. The canonical set is retained
at specs/issues/<ISSUE-ID>/ on main; Linear links to it and the original merged spec
PR, which keeps review history. Follow-up amendment PRs explain later direction changes.
Current architecture docs remain the authority for shipped behavior (BP-037).

Most valuable here: correctness on the second path (the legacy shape, the null
boundary, the concurrent case, the cancel path), anything deriving an auth or routing
decision from caller-controllable input, and a behaviour the tests assert around
rather than on.

Already settled upstream: the approach and every decision in the spec's DECISIONS.md
(human-approved — if one is wrong, say so as a spec finding and it gets folded back; don't
re-argue it inline), and the conventions in docs/contributing/best-practices.md.

Engineering calls
  • Route path GET /users/:userId/interrupted-requests. The spec did not name it. It sits beside POST /users/:userId/check-interrupted. If wrong: a rename in slice B before release, no other cost.
  • flowId on check-interrupted's list too, not only on the new read. The spec says "the interrupted list"; both lists now have the same entry shape. If wrong: one extra field.
  • The new read has no limit. It filters at the store by user, status and tenant (BP-033). A user with very many old interrupted records gets a long list. If wrong: add limit/offset later; additive.
  • interruptedAt falls back to updatedAt for a record that has no interruptedAt.
  • A relative URL works in createInProcessFetch. It resolves against a fixed internal origin, and only the path is read, as the spec says.
  • Docs. The engine README has the new routes and createInProcessFetch. The apps/docs pages in the spec's docs line (host adapters, connection resilience, the client tour) go with slice B, where the client's fetcher uses this. I had no agent-dispatch tool in this run, so I wrote the README text; it is not a docs-writer/docs-editor pass.
Verification

Red, then green, for each server behavior:

  • Status: sessionId + tenant check (engine/test/tenant-route-isolation.test.ts → "request status rejects a cross-tenant requestId"). Red: 3 failed: expected { id: 'req_1', …(3) } to match object { id: 'req_1', sessionId: 's' }, and expected 200 to be 404 twice (other tenant, no tenant header). Green: 3 passed.
  • Interrupted read (engine/test/recovery-routes.test.ts → "GET /users/:userId/interrupted-requests"; engine/test/user-route-scoping.test.ts). Red: 6 failed: route parses as not_found; reads expected 404 to be 200; check-interrupted entry has no flowId; the scoping harness reports list_interrupted_requests is not user-addressed. Green: 59 passed across the three files.
  • Blast radius of the scoping harness for the new route (negative assertions, so I broke the property and ran the whole engine suite):
    • Remove the tenant filter (source and per row): 1 test failed, "serves nothing to the same user and organization on another tenant" for this route. 4061 others passed.
    • Replace the row rule with tenant-only: 2 tests failed, "another organization" and "anonymous caller in a mixed app, against an authenticated flow's row" for this route. 4060 others passed.
  • createInProcessFetch (engine/test/in-process-fetch.test.ts). Red: 7 failed, createInProcessFetch is not a function. Green: 7 passed (path under default and custom basePath, decoded segments, 405 incl. HEAD, 404 outside basePath, 500 on failed init, a real action and status read with no server).
  • Pass-through of a host's Request. Red: node serve() tests failed 5 (500 from Hono onError) when the fetch always made a new Request. Green after the fix: node 70/70. The engine test "hands a Request with no init to the router untouched" pins it.
  • A host's Request is recognised by shape (CI fix). createInProcessFetch now recognises a host's Request by its url/method strings rather than instanceof, because test environments such as happy-dom replace the global Request. Regression test: engine/test/in-process-fetch.test.ts → "hands over a Request from another class by its URL, not as a stringified object".

Full runs on the final head:

  • pnpm --filter @flow-state-dev/engine test: 305 files, 4069 passed, 8 skipped.
  • pnpm --filter @flow-state-dev/node test: 7 files, 70 passed. Note: in this session the shell exported FSDEV_DEFAULT_MODEL=vercel/openai/gpt-5-nano, a form core now rejects, so every FlowState init failed. I ran node tests with that variable unset. It is an environment issue, not this change.
  • pnpm --filter @flow-state-dev/{engine,core,node} typecheck: exit 0.

Changeset: .changeset/interrupted-read-in-process-fetch.md (engine minor, core minor). Node has none: what it serves does not change.


Generated by Claude Code

The status read now answers the request's session id, and refuses a
request the caller does not reach (callerReachesRequest), the check the
abort and recovery routes already make.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLKy6E8CuEKEBwJURCEChf
…errupted list (FIX-2162)

GET /users/:userId/interrupted-requests lists the user's interrupted
request records on every call, whoever marked them; check-interrupted
stays the trigger. Both listings share one admission rule (tenant,
then the instance's own resolver, else the host rule). Both interrupted
lists name the instance id, falling back to the flow kind (BP-030).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLKy6E8CuEKEBwJURCEChf
…162)

The engine owns the one dispatch path: wait for the router (500 on init
failure), pick the handler by method (405 otherwise), read the route
from the URL's path under basePath (404 outside it), and hand the
Request through. node's createServerApp delegates its catch-all to it
and drops its own path derivation; health, dedicated routes, JSON
errors and dispose stay in node. README entries and changeset.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLKy6E8CuEKEBwJURCEChf
@vercel

vercel Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated
flow-state-dev-docs Ignored Ignored Oct 24, 2026 8:30pm UTC
flow-state-dev-kitchen-sink Ignored Ignored Oct 24, 2026 8:30pm UTC
flow-state-dev-ui Ignored Ignored Preview Oct 24, 2026 8:30pm UTC

Request Review

@linear-code

linear-code Bot commented Oct 24, 2026

Copy link
Copy Markdown

FIX-2162

Copy link
Copy Markdown
Collaborator Author

from: claude (issue-implement, FIX-2162 slice A)
session: https://claude.ai/code/session_01BLKy6E8CuEKEBwJURCEChf
kind: review-request

@codex review

Please look hardest at these areas:

  1. The tenant/owner check on request status (packages/engine/src/routes/request-status-routes.ts). It now uses callerReachesRequest, as abort/retry/continue do. Is there a path where a legitimate caller (DevTool, React watchdog, workforce) reads status without the tenant header it used for the send, and now gets 404?
  2. In-process fetch parity with node's old dispatch (packages/engine/src/routes/in-process-fetch.ts, packages/node/src/app.ts). Same 500 / 405 / path-decode rules; a Request with no init passes through untouched; a path outside basePath is 404. Any case where node's behavior changed (encoded basePath, trailing slash, bare mount, SSE, abort)?
  3. The shared row rule (listingAdmits in packages/engine/src/routes/recovery-routes.ts) now used by /active-requests and the new GET /users/:userId/interrupted-requests. Is the check order the same as before, and is anything leaked across org, tenant or the anonymous allow-list?

🤖 Generated with Claude Code

https://claude.ai/code/session_01BLKy6E8CuEKEBwJURCEChf


Generated by Claude Code

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T20:31:38.596574Z 197a760 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 3a6c9104df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…stanceof (FIX-2162)

createInProcessFetch checked `input instanceof Request`, so a host's Request
from another class (here: a shift-manager test that installs happy-dom's
globals, swapping the global Request out from under @hono/node-server's) was
stringified to "/[object Request]" and answered 404. The node host now
dispatches through this function, so every /api/flows call 404'd in that
test. Recognize a Request by its string url and method instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLKy6E8CuEKEBwJURCEChf

Copy link
Copy Markdown
Collaborator Author

CI: "Packed release installs and imports" is red, but not because of this PR.

The job fails in npm install of the packed tarballs with E404 GET https://registry.npmjs.org/@ai-sdk/provider/-/provider-4.0.34.tgz. @ai-sdk/provider@4.0.34 was published upstream at 2026-10-24T17:59:05Z and is now its latest tag, but npm still returns 404 for its tarball. The packed install resolves into an empty project with no lockfile, so it picks up that broken latest.

  • This PR changes no package.json and no pnpm-lock.yaml.
  • main fails the same job with the same 404 at 6ed7021 (job 120944830923).
  • No fix PR is open yet. It should clear on its own once npm serves the tarball, or upstream ships a new latest. If not, pin @ai-sdk/provider in the packed-install harness as a separate repo-wide change.

All other checks on d951088 passed; Kitchen-sink E2E is still running. I'll re-run the failed job once.


Generated by Claude Code

…removed

Retry starts a new request (metadata.retryOf on the successor) and leaves
the original interrupted, so it never drops off the listing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLKy6E8CuEKEBwJURCEChf
…removed

Retry starts a new request and leaves the original interrupted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLKy6E8CuEKEBwJURCEChf
@jhoffner
jhoffner marked this pull request as ready for review October 24, 2026 20:23

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 28daeb8e6b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ngifying it

createInProcessFetch recognised a foreign-class Request only when no init was
given; with any init it fell through to String(input), answered 404 and lost
the headers and body. It is now rebuilt the way new Request(request, init)
does, init's fields winning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BLKy6E8CuEKEBwJURCEChf
@jhoffner
jhoffner added this pull request to stack #3871 October 24, 2026 23:52
@jhoffner
jhoffner merged commit 691560f into main Oct 24, 2026
18 checks passed
@jhoffner
jhoffner deleted the fix/fix-2162-a branch October 24, 2026 23:57
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