Repository navigation
fix(daemon): accept a negative log offset for tail reads - #13
Merged
Merged
Conversation
GET /runs/:id/logs parsed offset with the non-negative num() helper, so Web's log tail request (offset=-16384) failed with 400 and the run page showed an empty log. records.readLog already documents a negative offset as tail bytes, and the Feishu watcher and CLI --tail rely on it. Parse offset with a new signed() helper; limit stays non-negative. Cover the tail read and non-integer offsets, and update the design note.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Run detail (Overview tab) showed "No output." for the Log tail card and fired two
400 Bad Requests on every load:Root cause:
GET /runs/:id/logsparsedoffsetwith the non-negativenum()helper (packages/orbit/src/daemon/http.ts), while the documented tail-read convention is a negative offset.records.readLog(packages/orbit/src/records/index.ts) already implements it (offset < 0 ? Math.max(0, size + offset) : Math.min(offset, size), plus skipping the first partial line), and three existing callers depend on it:packages/web/src/pages/run/Overview.tsx:api.logs(id, -16 * 1024, 16 * 1024)packages/orbit/src/feishu/index.ts:offset=-4096&limit=4096packages/orbit/src/cli/program.ts:-o.tail ? -o.tail : 0The route was the only place rejecting it. This fixes the contract at the daemon instead of changing the Web caller.
Changes
packages/orbit/src/daemon/http.ts: newsigned()query helper — a safe integer, negative allowed, raisingquery number must be a safe integerotherwise.packages/orbit/src/daemon/routes/runs.ts: parse the logoffsetwithsigned();limitstays non-negative vianum().packages/orbit/test/daemon.test.ts: drop the logoffsetentry from the rejects-negatives table; add a non-integer offset table (1.5,1e21,9007199254740992,NaN,Infinity,abc-> 400 "safe integer") and a tail-read test (-6->third\nwithnext19;-4096and0-> whole log).packages/orbit/test/security-api.test.ts: end-to-end tail read throughcreateAppon a terminal run (-6->{offset: 13, next: 19, text: "third\n"}), plus a fractional offset -> 400.docs/design.md: the numeric-query-parameter rule now states that only the logoffsetmay be negative (tail read) and the rest must be non-negative.Validation
Tested revision: this commit on top of
8e5cd9b. Windows 11, Node v22.19.0.biome check(changed files)tsc -p packages/orbit/tsconfig.json --noEmitvitest run packages/orbit/test/security-api.test.tsserves ordinary and empty files... refuses escaping linkscases (EPERM: operation not permitted, symlink), which fail on this box because it lacks symlink rights. The new tail-read case passes.vitest run packages/orbit/test/daemon.test.tspackages/orbit/src/lib/lock.tsreads/proc/<pid>/statfor the process start time, which does not exist on Windows, soacquireProcessLockthrowscannot determine process start time. Same forport.daemon.test.ts,bench.daemon.test.ts,cluster.daemon.test.ts.09:14:35 ... 09:14:44 [orbit] lease granted), with no remaining/api/error responses. Also checked a failed run and a running run.pnpm verifywas not run as a whole locally: this box has nopnpm, no Docker, and the daemon-based tests cannot start (see above). The CIverifyjob (ubuntu-24.04, Node 24.18) passed on this commit, includingpnpm smoke:package.pnpm verifypasses — run by CI on ubuntu-24.04 / Node 24.18 (jobverify, green); not run on the Windows dev box, see Validationdocs/design.mdquery-parameter rule)How to verify
git fetch origin && git switch fix/log-tail-offset pnpm install pnpm verifyThen in the Web UI open any finished run -> Overview: the Log tail card shows the tail instead of "No output."