Repository navigation
Description
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,
resolveRunLogreturnsnull, 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_runresult 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
- The no-runId path (
capturedRunId === null). The CLI emitsSEQUANT_RUN_IDwheneverSEQUANT_ORCHESTRATORis set (batch-executor.ts:310, called fromrun-orchestrator.ts:858), so only CLIs older than fix(mcp): log-file lookup races on concurrent runs and stale same-issue logs #631 reach it. - The in-process MCP engine (arch: in-process MCP engine — eliminate subprocess indirection and enable real-time streaming #508).
- Merging the run-log helpers (refactor(logs): one run-log module — parseLogFile, listLogFiles, resolveLogDir, formatDuration defined once #1471); this fix only changes which log
sequant_runaccepts. - Why the run could not write its log; a full disk is one cause, a killed run is another.
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
admarble commentedon Oct 19, 2026
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 unchangedmain:rgpattern matches the comment atrun.test.ts:1736today.Not vacuous. One tightening: for AC-1/AC-2, a
-tfilter 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).
Verdict: ✅ SCOPE_OK
Acceptance Criteria
AC-1: captured runId + miss ⇒
resolveRunLogreturnsnullVerification: 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())→ Thennull, and the stderr miss line is still emitted.Assumptions:
readRunLogByIdalready returns null for a miss, a corrupt file and an I/O error. All three now yieldnull.AC-2: result reports the missing log
Verification: Unit Test
Scenario: Given
resolveRunLogreturns null → When thesequant_runhandler 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 atrun.ts:837-860is 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:1717is 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)resolveRunLog(L234), on a captured-runId miss: keep theconsole.errorline, but reword it to "no fallback" andreturn null. Do not callreadLatestRunLog. Update the doc comment (L226-232). The no-runId path stays untouched (Non-Goal).readRunLogById3× 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)buildFallbackResponse/RunToolResponsewithrunLogMissing: trueand arequestedIssues: number[]. Add anotestring such as "Run log not found for runId ; result is not a parsed log (issues #A, #B)".issues: []stays. Passissuesand 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.summary.passedfor 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)"captured runId miss never returns another run". Assertnull, thelookup missstderr line, and that the other log's content is never read."missing run log is reported in the result": invoke the handler (or the exported builder) and assertrequestedIssues, the not-found text andrunLogMissing.run.ts.Design Review
resolveRunLogis the single resolver, and the response builder sits next to it in the same file.nullon 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.resolveRunLoghas one production caller,run.ts:837.readLatestRunLogstays exported and is still used on the no-runId path.RunToolResponseis consumed only as JSON text by MCP clients. The new fields are additive. Grepsrc/anddocs/forRunToolResponseandrawOutputdocumentation before editing, to update any MCP docs.Feature Quality Planning
All standard checks pass. Notable items:
issues/summaryare unaffected.readLatestRunLogfallback, confirm only that test fails, restore, and recordMutation-verified: AC-1 — …with the file-path-firstfailedTest.Open Questions
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
buglabel means targeted tests are enough. No UI.Label Review
Current: bug
Recommended: bug, planned
Quality Loop: Won't auto-enable (SCOPE_OK).
admarble commentedon Oct 19, 2026
QA Verdict: AC_MET_BUT_NOT_A_PLUS
AC coverage: 3/3 met
Gaps:
docs/features/mcp-server.md:259-287documents thesequant_runresponse and its fallback, but does not listrunLogMissing,requestedIssuesornote. A caller can only find these fields by reading the code.Suggestions:
capturedRunIdhas 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.docs(#1515): document runLogMissing, requestedIssues and note on the …