Repository navigation
🔗 fix: Refuse Uploads and Fail Readiness When the File Server Uses Another Redis - #398
Conversation
…other Redis The API registers each upload session in Redis and the file server reads it back to write the `upload:` record that later authorizes the object. Nothing enforced that the two share a Redis. A file server on another Redis found no session, stored the object anyway under `upload:null…`, and reported success; every later download, execution input and `import_file` was then refused. - File server: refuse an upload whose session is not in its Redis with `409 UPLOAD_SESSION_UNKNOWN`, store nothing, and log the cause. - API: check at startup that `FILE_SERVER_URL` sees a short-lived random key written to the API's Redis, through the authenticated `POST /internal/store-probe`. A confirmed mismatch makes `/v1/health` answer 503 until a re-check passes. An unreachable or older file server is inconclusive: one warning, background retries, never a failure. - Document the pairing requirement in the remote-bridge guide.
|
@codex review |
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. 🎉 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
@codex review This is the final review pass for this PR, at head 145d904. Please report anything still outstanding: correctness of the file server's unknown-session refusal on both upload routes, the store probe's auth and timeout bounds, the health gating and its version-skew behavior, and the tests. |
|
Codex Review: Didn't find any major issues. Keep it up! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
Code API and the file server it forwards uploads to must share one Redis. Nothing enforced that or wrote it down, and a pair that did not share one kept answering 200 while every upload it accepted was unusable. This change makes that pairing fail at upload time and at the health check.
What broke
/uploadand/upload/batch, the API writessession:<session_id>to its Redis and forwards the bytes toFILE_SERVER_URL.session:<session_id>from its own Redis and writesupload:<sessionKey><session_id><fileId>there./execinput and a workspaceimport_fileare each authorized only if that record exists, under that session key, in the API's Redis.A deployment paired a remote-bridge API that had its own Redis with another tier's file server, which used a different one. The file server found no session, stored each object anyway, wrote the record as
upload:null<session_id><fileId>, and answered 200.How it stayed silent
import_filereturned403 IMPORT_SOURCE_UNAUTHORIZED, which reads as an ownership problem, not a deployment one.What happens now
1. The file server refuses an upload whose session is not in its Redis.
It answers
409 UPLOAD_SESSION_UNKNOWN, stores nothing, writes no record, and logs an error naming the likely cause (API and file server on different Redis instances, or a session older thanSESSION_CACHE_TTL). Both upload routes go through the same check. The multipart route previously swallowed per-file errors and answered 200 with an empty list; for this error it now answers 409.Existing callers already treat a failed upload as a failure, so no caller changes were needed:
/upload/upload/batchWhy refuse instead of keeping the bytes and skipping the record: I traced every path that uploads to the file server, and each one has its session registered by the API first.
/upload,/upload/batchrecordSessionOwnership, awaited before the bytes are forwarded/execand the programmatic routes, before the job is queued; a grant can only write to that output sessionmax_upload_bytes: 0)So an unknown session means the Redis is not shared, the session outlived
SESSION_CACHE_TTL, or Redis lost the key. In all three the stored object would be unreadable through every route: each reader requires the record under the real session key, reads also require the livesession:key, and nothing recreates upload records (rehydrate-session-cache.tsrestores session keys only). Keeping the object would only leave bytes nobody can read, which in the reported case landed in another deployment's bucket. No authorization check was changed or relaxed.2. The API checks the pairing at startup and reports a mismatch through
/v1/health.The API writes a random key with a 60-second TTL to its Redis and asks the file server, over a new route behind the existing internal-service auth (
X-CodeAPI-Internal-Token), whether it can see it./v1/healthanswers 503 with{"status":"not ready","checks":{"fileServerStore":"mismatch"}}; re-checked every 30 seconds and cleared as soon as the file server is corrected, without an API restartI gated
/v1/healthinstead of exiting at startup. It is the API's only health endpoint, the Helm chart and Compose files already use it as the readiness signal, and it already reports an unreachable Redis as 503. Exiting would also turn one bad probe into a crash and would need a restart to recover after the file server is fixed. The Helm chart uses the same path for liveness, so a mismatched pod is also restarted until the pairing is corrected.Startup waits only for the first result, and each probe is bounded at 5 seconds end to end, including the Redis write (the API's client queues commands while disconnected). Only the random id is sent; the file server derives the
store-probe:<id>key itself, so the route cannot be used to test for any other key. Neither the key nor the token is logged.CODEAPI_FILE_SERVER_STORE_CHECK=falseskips the startup check; the file server's refusal is not configurable.3. The remote-bridge guide documents the requirement and what the two checks report, with a matching entry under common failures in the worker runbook.
Version skew
Not covered
local-api.ts, the development-only entry point, does not run the startup check.EGRESS_GATEWAY_FILE_SERVER_URLnames a different file server than the API'sFILE_SERVER_URLis not probed. The file server's own refusal still applies to it.Change Type
Testing
file-server.test.tsstarts the real file server process against a real Redis. Only S3 is stubbed, and only for the calls a zero-byte upload makes. It covers:upload:key in either Redis, the cause in the file server log, import still refused, and the probe reports split;store-pairing.test.tsruns the probe and the monitor against two real Redis instances and the real probe router over HTTP. It covers shared, split with recovery after correction, an older file server without the route (API healthy, one warning), a file server that comes up late, both timeouts, probe-key expiry, a single contradicted mismatch, and the/v1/healthresponses.main, all fivefile-server.test.tstests fail.lifecycle.tscall sites and the/v1/healthwiring inapi-server.tsandservice-api.tsare not run by a test (those modules open the production Redis connection on import); the handler and the monitor they call are. No deployment was touched.Test Configuration
bun run test: 1263 pass, 17 skip, 5 fail. The same five (job-cancellation-commit.test.ts,tool-input-signature.test.ts) fail identically on an untouchedmaincheckout on this machine. One earlier run also failed a timing-dependent case inbridge/workspace-store.test.ts, which passed alone three times and in the next full run.tscreports the same 7 errors asmain, none in a file this PR touches. ESLint is clean on the new files.Checklist