Skip to content

fix(cli): lore logs -f streams new lines (bypass bridge for legacy's never-resolving promise) - #1579

Merged
BYK merged 2 commits into
mainfrom
fix/lore-logs-follow
Aug 5, 2026
Merged

BYK merged 2 commits into
mainfrom
fix/lore-logs-follow

Conversation

@BYK

@BYK BYK commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Summary

Fixes the user-reported bug: lore logs -f printed nothing because the typed wrapper hung trying to await the legacy's non-resolving promise.

What's in this PR

Bug

The typed commands/logs.ts routed both non-follow and follow invocations through the shared runLegacyAndCollect bridge. The bridge's await call() blocks until the legacy function returns. The legacy's commandLogs (in packages/gateway/src/cli/logs.ts) deliberately returns new Promise(() => {}) after installing the watchFile poller + SIGINT/SIGTERM cleanup — it NEVER resolves. Result: lore logs -f blocked forever, and the user saw an empty terminal.

Fix

Split the handler into two execution paths based on whether follow is set.

  • Non-follow path (logs, logs -n 10, etc.): unchanged. Bridge wrapper. Initial read is synchronous, returns cleanly.
  • Follow path (logs -f): invoke the legacy WITHOUT await. The legacy's initial read is fully synchronous (readFileSync + split\('\n') + console.log of the tail) BEFORE any control-flow suspension (lines 62-68 of the legacy handler). The watchFile poller + signal handlers keep Node alive on the event loop; the default SIGINT handler exits on Ctrl-C.

The typed output envelope for the follow path is empty (data: ''), since the streaming stdout IS the output — there's nothing to capture in a request/response envelope. This is documented in the file header as the one typed command with a non-standard output shape.

Test updates

The old -f test was designed for the bridge-based wrapper. It mocked commandLogs but didn't pin that the wrapper actually returns vs. hangs. Rewrote to:

  1. Forward values.follow=true + values.f=true to the legacy (mock verified — covers alias wiring).
  2. Promise.race against a 2-second timeout — fails loudly if the wrapper hangs (which is the user-facing bug).
  3. Cleanly tear down SIGINT/SIGTERM listeners installed by the legacy so the test process can exit.
  4. vi.doUnmock + vi.resetModules cleanup.

Verification

  • 215 CLI tests pass across 22 files (the -f test was rewritten in place; no count change).
  • TypeScript clean.
  • Lint clean (zero errors).
  • Format clean.
  • Bundle succeeds for both CJS (Node) and ESM (Bun) targets.

Notes

  • This is the only typed command that does not funnel through buildOutputCommand for one of its code paths. The follow-mode's streaming-until-Ctrl-C shape is incompatible with the request/response envelope.
  • The -f help text already advertised the behavior correctly ("Tail the log and print new lines as they arrive (Ctrl-C to stop)"). The fix makes the runtime match the docs.
  • Future refactor: expose commandLogs's initial tail as a separate exported function so the typed wrapper doesn't need to defer to the legacy at all for the follow path. Trivial refactor, deferred.

…never-resolving promise)

Bug: `lore logs -f` printed nothing. The typed wrapper delegated
to the legacy `commandLogs` via the shared `runLegacyAndCollect`
bridge, which `await`s the legacy function. The legacy deliberately
returns `new Promise(() => {})` after installing the watchFile
poller + SIGINT/SIGTERM cleanup — i.e. it NEVER resolves. So the
bridge hung forever on -f, and the user saw an empty terminal.

Fix: split the handler into two execution paths.

Non-follow: bridge wrapper, as before (synchronous initial read,
returns cleanly).

Follow (-f / --follow): invoke the legacy WITHOUT await. The
legacy's initial read is fully synchronous (readFileSync + split +
console.log of tail) BEFORE any control-flow suspension; the
watchFile poller + signal handlers keep the Node process alive on
the event loop; the default SIGINT handler exits the process on
Ctrl-C.

This is the only typed command that does not funnel through
`buildOutputCommand` for one of its code paths — the streaming
follow-mode is request/streamship-shaped, not
request/response-shaped. Documented in the file header.

Test updates:
- The old `-f` test was written for the bridge-based wrapper. It
  mocked commandLogs but didn't pin that the wrapper actually returns
  (vs. hangs). Rewrote to:
    1. Forward the same values to the legacy (mock verified)
    2. `Promise.race` against a 2s timeout — fails if the wrapper
       hangs (the user-facing bug)
    3. Cleanly tear down SIGINT/SIGTERM listeners installed by the
       legacy so the test process can exit
    4. Mock cleanup via `vi.doUnmock` + `vi.resetModules`

All gates green: 215 CLI tests pass across 22 files, TypeScript
clean, lint clean (zero errors), format clean, bundle succeeds.
@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codecov Results 📊

✅ Patch coverage is 88.89%. Project has 6917 uncovered lines.
✅ Project coverage is 76.39%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
packages/gateway/src/cli/commands/logs.ts 88.89% ⚠️ 1 Missing
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    76.38%    76.39%    +0.01%
==========================================
  Files          198       198         —
  Lines        29296     29300        +4
  Branches     21173     21175        +2
==========================================
+ Hits         22378     22383        +5
- Misses        6918      6917        -1
- Partials      2177      2178        +1

Generated by Codecov Action

…eview)

Independent adversarial review on PR #1579 found two load-bearing
gaps in the regression test for the `-f`/follow fix:

CRITICAL #1: The mock commandLogs returned synchronously (so the
Promise.race timeout never fired against the actual user-facing
regression — a revert to `await` would pass the test). Changed
the mock to return `new Promise<void>(() => {})` so the test
faithfully simulates the real legacy's never-resolving watchFile
promise. The wrapper's `void` discard (not `await`) is now
genuinely load-bearing.

CRITICAL #2: The test only asserted `logsImpl` was called once
(`toHaveBeenCalledTimes(1)`), not what was forwarded. A regression
that drops `values.f = flags.follow` would silently pass. Added
explicit assertion:

  expect(callArgs[1]).toMatchObject({
    follow: true,
    f: true,
    lines: 50,
    n: 50,
  })

Confirmed load-bearing by mutation: removing `values.f = flags.follow`
from the handler makes the test fail with 'expected ... to match
object { follow: true, f: true, ... }'.

MEDIUM #3 (production code): The follow path returned
`{ kind: "value", data: "" }` which the typed output pipeline
emits as `"\n` in human mode or `{ "output": "" }\n` in JSON
mode (after the legacy's raw stdout). Changed to
`{ kind: "empty" }` — `empty` is the canonical 'no envelope to
render' shape that writes nothing.

LOW #4 (production code): Added a defensive `.catch()` on the
fire-and-forget `void commandLogs([])` so a future legacy path that
throws (instead of `process.exit(1)`) doesn't go to an unhandled
rejection.

Cleanup #6 (test code): Removed the redundant
`Promise.resolve(runCli())` wrapping (cleanup #6 from review).
The runtime Promise.race handles Promise and value inputs the same
way.

Lint: oxlint-disable-next-line used on the no-misused-promises
violation (matches the established pattern in
`background-limiter.test.ts:376`).

All gates green: 215 CLI tests pass across 22 files, TypeScript
clean, lint clean (zero errors), format clean, bundle succeeds.
@BYK
BYK merged commit f574c03 into main Aug 5, 2026
24 checks passed
@BYK
BYK deleted the fix/lore-logs-follow branch August 5, 2026 13:52
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-08-05 13:52 UTC

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