Skip to content

Local CLI prompt hooks receive an empty @calls history (daemon call records are not collected locally) #9349

Closed

Description

@dezren39

Problem

For local mcpx exec / mcpx run (CLI localService, pkgs/mcpx/internal/cli/exec.go), a prompt hook whose template references @calls always receives [], even when the script successfully called tools.

Root cause (Codex review finding on PR #9021, 2026-11-13): localService never initializes svc.Calls, and the daemon's CallRegistry is a live, in-process, per-run sink registry with no retention and no cross-process query surface. A local run's tool calls execute through the separate daemon process (reported via X-Mcpx-Run to the daemon's registry), so there is currently no path for the local service's hook context to learn them. RunWith populates its call snapshot only inside if s.Calls != nil, so local hooks silently present an uncollected history as "no calls".

Daemon-side runs are unaffected: routes_exec.go stamps the daemon's shared registry (Calls: s.callRegistry()), and their @calls is populated.

What a fix needs (design first)

One of, or a combination of:

  1. Daemon retains per-run CallInfo records (bounded, TTL'd) and exposes a query surface for a run's calls that the CLI can fetch before outcome hooks run; the CLI wires a fetch into the local service's hook-context snapshot.
  2. The generated client / call path reports call frames back to the local process as they complete, and the local service registers a registry the runner actually feeds.

Either way: never present an uncollected history as an empty one — if calls cannot be collected for a run, the hook path should say so (frame warning or a documented placeholder behaviour) rather than substituting [] silently.

Acceptance

  • A local mcpx exec/mcpx run with an outcome prompt hook referencing @calls receives the run's actual tool calls (server, tool, args hash, duration, ok/error — the existing CallInfo shape, hashed args only).
  • A regression test covers a local run whose script calls a tool and whose outcome prompt hook observes it in @calls.
  • Daemon-run behaviour is unchanged; the existing execsvc/cli/daemon suites pass.

Provenance

Split out of issue #5276 / PR #9021 during queue task 9174 (lane any-c, 2026-11-13): the nested-sampling half of that Codex round was fixed in PR #9021; this half needs a new cross-process collection surface and was deferred with the reason recorded on the PR thread rather than rushed into the advise-hooks slice.

Activity

  1. added
    task/small-fixQueue packet kind: bounded fix with reproduction and targeted tests
    source/queue-workerFiled or worked by the queue/worker pilot
    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)
    on Nov 13, 2026
  2. developing-today commented on Nov 13, 2026

    @developing-today
    Contributor
  3. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    agent-note:v1 — triage by lane any-a (queue task 18928), at 2026-11-17T05:15Z. Verdict: CONFIRMED, real and unstarted.

    Verified on current main:

    • pkgs/mcpx/internal/cli/exec.go localService (~line 178) builds the execsvc.Service with Store/Local/Limits and model-provider wiring but never sets Calls:.
    • pkgs/mcpx/internal/execsvc/execsvc.go RunWith (~line 1060) populates the run's call snapshot only if s.Calls != nil — so a local run's outcome prompt hook receives an empty snapshot that reads as "no calls".
    • Contrast: pkgs/mcpx/internal/daemon/routes_exec.go (~line 260) stamps Calls: s.callRegistry(), so daemon-side runs populate @Calls. Only local CLI runs are affected, exactly as reported. No fix attempted yet; no PR.

    Routing: follow-on fix enqueued as queue task 20377 (small_fix) carrying the issue's acceptance, including the hard rule that an uncollected history must be signalled, never silently presented as []. The fix is design-first per the issue (daemon-retained per-run CallInfo + query surface, or client-reported frames).

  4. added
    status/triagedTriaged and routed (see agent note)
    priority/normalOrdinary priority (the default)
    effort/mMedium: expected under 1 day of work
    kind/bugSomething isn't working (prefixed form of the classic bug label)
    on Nov 17, 2026
  5. dezren39 commented on Nov 17, 2026

    @dezren39
    MemberAuthor

    🤖 Agent note · picked up and parked — task 20377 (openchamber scheduled lane any-o)

  6. added
    work/assignedQueue worker lifecycle state
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    status/parkedDeliberately paused with a recorded resume condition
    on Nov 17, 2026
  7. 109 remaining items

  8. added
    queue/claimedQueue worker lifecycle state
    and removed
    status/parkedDeliberately paused with a recorded resume condition
    queue/parkedQueue task is parked (waiting on CI, time, or an event)
    on Nov 20, 2026
  9. dezren39 commented on Nov 20, 2026

    @dezren39
    MemberAuthor

    PR opened: #12117 (commit 58b9460). The local CLI now registers bounded daemon-side call history, fetches the hashed-only snapshot before outcome hooks, and reports collection failures explicitly instead of substituting an empty @Calls list. Targeted execsvc/CLI/daemon tests and race/shuffle regression tests passed.

  10. dezren39 commented on Nov 22, 2026

    @dezren39
    MemberAuthor

    Merged work, still open. Every pull request that references this issue has merged (#12061, #12117, #12201) and none is open, but the issue kept status:in-review. Tasks that name it as a blocker have been waiting on it.

    status:in-review is removed. Whoever takes this next: run the issue's done check against main. Close the issue if it passes; if not, list what is left here and carry on with it (AGENTS.md, "Finishing work").

    By: Claude, 2026-11-22 flow review.


    Generated by Claude Code

  11. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: picked_up
    lane: GV (sandbox fix lane, worker archer)

    Claiming #9349 for implementation. Premise verified fresh 2026-11-23: issue OPEN, no live claim (prior notes are Nov 17–19 parks of task 20377, long lapsed), bug present on current main (localService in pkgs/mcpx/internal/cli/exec.go never initializes svc.Calls).

    Plan: inspect the daemon CallRegistry + routes_exec stamping and the local exec path; land the smallest cross-process collection surface that satisfies the acceptance (local run's outcome hook observes the run's actual calls in @calls), with the regression test named in the issue. Never present an uncollected history as an empty one.

  12. dezren39 commented on Nov 23, 2026

    @dezren39
    MemberAuthor

    agent-note:v1
    state: done
    lane: GV (sandbox fix lane, worker archer)

    Done-check close-out: the fix for #9349 already landed; verified end to end on current main. Closing as completed.

    What landed (option 1 from the issue — daemon retains per-run records + a query surface the CLI fetches before outcome hooks):

    • 58b94607e8d "Collect local run tool calls for outcome hooks" (2026-11-20) — verified ancestor of current main. Daemon: bounded, TTL'd per-run CallRegistry history (BeginHistory/History, prune + retention limits); routes POST /v1/calls/{run} (begin) and GET /v1/calls/{run} (snapshot) in internal/daemon/server.go, catalogued in internal/api/ops.go. CLI: Client.Begin/Client.Snapshot in internal/cli/exec.go; localService wires CallHistory: c. execsvc: RunWith calls CallHistory.Begin before the script starts and Snapshot before outcome hooks.
    • c43b796e622 "fix(mcpx): end a daemon run's call history when it unregisters" (2026-11-21) — lifecycle follow-up.
    • The never-silent-empty rule is implemented: a failed begin/snapshot surfaces to hooks as an unavailable @calls (CallsError), and the client rejects available:false / truncated snapshots with an error rather than substituting [].

    Acceptance, checked one by one:

    • Local run's outcome prompt hook observes the run's actual calls in @calls (CallInfo shape, hashed args only): covered by the regression test below and the wiring above.
    • Regression test: TestLocalOutcomePromptGetsCollectedCallsAndExplicitUnavailable (internal/execsvc/call_history_test.go) — collected calls reach the prompt ("tool":"forecast" present, "calls":[] absent); snapshot failure and begin failure both yield "available":false, never "calls":[]. Daemon side: TestCallHistoryHandlersDistinguishMissingEmptyAndCollected (internal/daemon/call_history_test.go).
    • Daemon-run behaviour unchanged; suites pass (laptop worktree off origin/main @ dec4e88, 2026-11-23): go test ./internal/execsvc/ ok; ./internal/daemon/ ok (248s); ./internal/cli/ ok — one unrelated timing test (TestInlineDaemonCancelledWhileWaiting, a mcpx: inlineDaemon's cancel-during-poll path (PR #320) has no regression test — ablating it leaves the suite green #323 regression with a 2s wall-clock assertion) failed twice under laptop load ~90 and passed on re-run (2.37s); recorded here as a load flake, not a defect in this change (the worktree carried no code changes).

    No PR from this lane: there was nothing left to implement. The issue stayed open only because the landing was never reconciled against it.

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

    app/mcpxPackage/app: mcpx (pkgs/ or apps/ in this repo)effort/mMedium: expected under 1 day of workkind/bugSomething isn't working (prefixed form of the classic bug label)priority/normalOrdinary priority (the default)source/queue-workerFiled or worked by the queue/worker pilotstatus:donetask/small-fixQueue packet kind: bounded fix with reproduction and targeted tests

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions