Skip to content

fix(mcp): sequant_run reports another run's issues and verdict when its own run log is missing — a runId lookup miss falls back to the time window #1515

Closed

Description

@admarble

Problem

When sequant_run captured its run's runId but no log file with that id exists, the MCP result reports another run's issues and verdict as its own. resolveRunLog (src/mcp/tools/run.ts:234) falls back to readLatestRunLog(runStartTime) on a runId lookup miss. That fallback takes the newest log whose filename time is at most 5 minutes before this run's start, whatever its runId or issues.

#631 added the runId lookup to stop exactly this. Its AC-4 limited the time-window fallback to the case where no runId was captured. The #631 follow-up also used it on a lookup miss, and a test pins that behaviour: run.test.ts > "falls back to readLatestRunLog when capturedRunId is set but lookup misses" expects the other run's log back.

Field case (graph-2026-10-freeze-c, 2026-10-17). Three sequant_run calls ran in parallel for #1482, #1486 and #1488. The disk filled, so the #1486 and #1488 runs wrote no log. Both MCP results showed #1482's issue and QA verdict. The only sign was a [mcp:run] … lookup miss line on the MCP server's own stderr, which the caller never sees.

Repro on main (0b764c0). Copy any real run log into an empty .sequant/logs/ under a filename with the current time and a different runId. Then call resolveRunLog("<a runId with no file>", new Date()) (via tsx). It returns the copied log: issues [1484], runId a16504cb-…. The correct result is null, which gives the caller the fallback response for its own issues.

Acceptance Criteria

  • AC-1: When a runId was captured and no log with that runId is found, resolveRunLog returns null, never a log with a different runId. Evidence: npx vitest run src/mcp/tools/run.test.ts -t "captured runId miss never returns another run" → ≥ 1 passed, 0 failed.
  • AC-2: On that miss, the sequant_run result names the requested issues and says the run log was not found, so the caller can tell its result is not a parsed log. Evidence: npx vitest run src/mcp/tools/run.test.ts -t "missing run log is reported in the result" → ≥ 1 passed, 0 failed.
  • AC-3: The test that pins the old behaviour is rewritten to assert AC-1. Evidence: rg -n 'Fell back to readLatestRunLog and returned the other-run log' src/mcp/tools/run.test.ts → no output.

Approach note

The lookup-miss fallback was meant to cover a log that is not on disk yet. If that still matters, retry readRunLogById briefly before returning null; do not widen the match.

Non-Goals

May touch

src/mcp/tools/run.ts, src/mcp/tools/run.test.ts, CHANGELOG. Serialize with #1471 and #1472, which also edit src/mcp/tools/run.ts.

Activity

  1. added
    bug
    on Oct 18, 2026
  2. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    Complexity: Standard (3 ACs, 1 directory: src/mcp/tools/)

    AC Quality Check

    All three ACs are single-line and carry an Evidence: clause. Each Evidence command fails on unchanged main:

    • AC-1, AC-2: the named tests don't exist, so vitest finds 0 matches.
    • AC-3: the rg pattern matches the comment at run.test.ts:1736 today.

    Not vacuous. One tightening: for AC-1/AC-2, a -t filter that matches nothing may exit 0 in some vitest configs. Check "≥ 1 passed" in the output, not only the exit code.

    Scope Assessment

    Non-Goals: present in the issue (no-runId path, in-process engine #508, #1471 helper merge, why the log is missing).

    Metric Value Status
    Feature count 1 ✅
    AC items 3 ✅
    Directory spread 1 ✅

    Verdict: ✅ SCOPE_OK

    Acceptance Criteria

    AC-1: captured runId + miss ⇒ resolveRunLog returns null

    Verification: Unit Test
    Scenario: Given a captured runId and only another run's log on disk, with a filename inside the 5-min window → When resolveRunLog(id, new Date()) → Then null, and the stderr miss line is still emitted.
    Assumptions: readRunLogById already returns null for a miss, a corrupt file and an I/O error. All three now yield null.

    AC-2: result reports the missing log

    Verification: Unit Test
    Scenario: Given resolveRunLog returns null → When the sequant_run handler builds its response → Then the response names the requested issues and says the run log was not found.
    Assumptions: buildFallbackResponse (run.ts:432) is module-private, and the handler at run.ts:837-860 is only reachable through the registered tool. The test must go through the handler, or export a small helper.

    AC-3: rewrite the pinning test

    Verification: Unit Test (grep gate)
    Scenario: The test at run.test.ts:1717 is rewritten to assert AC-1, and the string "Fell back to readLatestRunLog and returned the other-run log" is gone.

    Implementation Plan

    Phase 1: Resolver (src/mcp/tools/run.ts)

    1. In resolveRunLog (L234), on a captured-runId miss: keep the console.error line, but reword it to "no fallback" and return null. Do not call readLatestRunLog. Update the doc comment (L226-232). The no-runId path stays untouched (Non-Goal).
    2. Optional retry for a log that is not on disk yet: poll readRunLogById 3× at ~200 ms before giving up. Recommend including it, because the issue's approach note allows it and the cost is small. Make the delay injectable or use fake timers so tests stay fast. It must never widen the match.

    Phase 2: Response (run.ts)

    1. Extend buildFallbackResponse / RunToolResponse with runLogMissing: true and a requestedIssues: number[]. Add a note string such as "Run log not found for runId ; result is not a parsed log (issues #A, #B)". issues: [] stays. Pass issues and the captured runId from the handler. Decide whether the generic "no runId" fallback also gets the flag. Recommend yes, since it is also not a parsed log, but only if that stays a one-line change.
    2. Check that summary.passed for a missing log doesn't claim success per issue. Today it counts all issues as passed when the exit code is 0. The note must make that unmistakable.

    Phase 3: Tests (run.test.ts)

    1. Replace L1717 with "captured runId miss never returns another run". Assert null, the lookup miss stderr line, and that the other log's content is never read.
    2. Add "missing run log is reported in the result": invoke the handler (or the exported builder) and assert requestedIssues, the not-found text and runLogMissing.
    3. CHANGELOG entry. Serialize with refactor(logs): one run-log module — parseLogFile, listLogFiles, resolveLogDir, formatDuration defined once #1471/refactor(drivers,mcp): one killProcessGroup(child, { graceMs }) with SIGKILL escalation; pushLines on RingBuffer (closes the AsyncSubprocess trigger) #1472, which also edit run.ts.

    Design Review

    1. Where does this belong? resolveRunLog is the single resolver, and the response builder sits next to it in the same file.
    2. Simplest correct approach? Return null on a captured-runId miss. Rejected: matching the fallback log's issues against the requested issues. That still picks the wrong log when two concurrent runs share an issue, and the field case was concurrent runs.
    3. Existing pattern / re-patch count? Pattern: exact-key lookup, with a time window only as a last resort. Prior history: fix(mcp): log-file lookup races on concurrent runs and stale same-issue logs #631 added the runId lookup, and its follow-up re-added the window fallback on a miss (the bug here). That is one fix and one regression-by-follow-up, so the count is below the 2-fix stop threshold. This fix makes the AC-4 intent of fix(mcp): log-file lookup races on concurrent runs and stale same-issue logs #631 true.
    4. Reviewer challenge? "Why not retry longer?" Answer: the log is written before the CLI exits, so a short retry covers fsync lag and anything longer hides a real failure. "Why not fix the disk-full case?" That is a Non-Goal.
    5. Producers/consumers: resolveRunLog has one production caller, run.ts:837. readLatestRunLog stays exported and is still used on the no-runId path. RunToolResponse is consumed only as JSON text by MCP clients. The new fields are additive. Grep src/ and docs/ for RunToolResponse and rawOutput documentation before editing, to update any MCP docs.

    Feature Quality Planning

    All standard checks pass. Notable items:

    • Backward compatibility: the added fields are additive, so existing callers that read issues/summary are unaffected.
    • Other tests in the "resolveRunLog" block (L1493+) assume the fallback. Re-read the block, since "returns null when both … miss" should still pass.
    • Mutation-verify the AC-1 gate test (CLAUDE.md Testing): restore the readLatestRunLog fallback, confirm only that test fails, restore, and record Mutation-verified: AC-1 — … with the file-path-first failedTest.

    Open Questions

    1. Retry before returning null? Recommendation: yes, 3×200 ms, injectable. Impact if wrong: a few hundred ms of extra latency on a miss, or a race on a slow fsync if omitted.
    2. Flag the no-runId fallback too (runLogMissing)? Recommendation: yes, if the change is one line. Impact: none on the AC set.

    Recommended Workflow

    Phases: exec → qa
    Quality Loop: disabled
    Reasoning: A small bug fix in one file with Unit Test ACs. testgen is skipped because the bug label means targeted tests are enough. No UI.

    Label Review

    Current: bug
    Recommended: bug, planned
    Quality Loop: Won't auto-enable (SCOPE_OK).

  3. added
    planned
    on Oct 19, 2026
  4. admarble commented on Oct 19, 2026

    @admarble
    ContributorAuthor

    QA Verdict: AC_MET_BUT_NOT_A_PLUS

    AC coverage: 3/3 met

    Gaps:

    • MCP sequant_run docs do not document runLogMissing, requestedIssues and note on the fallback response — fixed in this PR
    • capturedRunId wiring from the handler into the fallback response is untested — dropped: one-line pass-through, builder and resolver covered
    • Required test CI check had not completed when QA finished
    • docs/features/mcp-server.md:259-287 documents the sequant_run response and its fallback, but does not list runLogMissing, requestedIssues or note. A caller can only find these fields by reading the code.

    Suggestions:

    • The handler-level wiring of capturedRunId has no test. AC-2 is tested through the exported builder. The PR body names this as its weakest part, and it is a one-line pass-through.
  5. added a commit that references this issue on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugplanned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions