* fix(agentctl): start per-repo workspace trackers in passthrough mode
CLI passthrough mode starts the agent CLI via the PTY-based
InteractiveRunner instead of agentctl's startAgent / startOneShot, so the
per-repo workspace trackers created for multi-repo task roots were never
started. The bare root tracker exits immediately because it has no git
index, leaving polling completely idle — file edits made by the agent
never produced workspace-stream notifications and the Files panel stayed
stale. Move the tracker startup to instance.Manager.CreateInstance via a
new StartAllWorkspaceTrackers helper so polling fires for every repo
regardless of whether the agent runs via ACP or passthrough.
Fixes#982
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(lifecycle): serialize workspace poll-mode pushes to prevent slow-stuck mode
When a session subscribes and then immediately focuses (the normal page-load
sequence), the workspace poll aggregator used to spawn two independent
goroutines — one pushing slow, one pushing fast — whose HTTP arrival order
at agentctl was undefined. With the slow request landing after the fast
request the tracker ended up in slow mode (~30s polling) while the
aggregator's lastPushed claimed fast, and the suppress-duplicate guard then
blocked any future focus event from reconciling the divergence. Multi-repo
passthrough sessions hit this every page load: the Files panel saw
~30s-stale state even with the per-repo trackers running.
Replace the fire-and-forget goroutine per push with a single in-flight
pusher per workspace plus a last-write-wins pending slot — concurrent
callers all converge on the same pusher, which drains the queue in order
so the final queued mode is what reaches the wire last.
Regression test in manager_subscription_test.go simulates the race with an
httptest server that adds artificial latency on slow pushes; the test
fails on the old parallel-goroutine implementation and passes on the
serialized one.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(agentctl): address PR review feedback for passthrough tracker fix
- Goroutine leak: extract stopWorkspaceTrackers() and call it
unconditionally at the top of Manager.Stop(). Previously the early
return when status==Stopped skipped tracker teardown in passthrough
mode (where Start() never runs), leaking 2 goroutines per per-repo
tracker per stopped instance. stopShellAndProcesses delegates to the
same helper.
- Trim multi-line doc comments to one-liners per CLAUDE.md (the
StartAllWorkspaceTrackers docstring and the CreateInstance call-site
comment).
- Replace the fixed time.Sleep in the race regression test with a poll
on len(calls), exiting as soon as the pusher has drained, plus a
brief settle window after to keep the test sensitive to the late
racing slow push the fix guards against.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(web): refresh expanded subtrees on polling-detected file changes
The agentctl workspace tracker emits a generic `refresh` event with empty
path when its poll cycle detects file changes (it knows something changed
but not which file). The Files panel previously only refreshed the root
folder on these events, so files added under an expanded subdir never
became visible — the merge preserved the stale subtree, and the user had
to manually collapse + re-expand to see new files.
This is the user-visible symptom of #982 (Files panel does not refresh
after agent makes changes in CLI passthrough mode): the backend fixes in
this PR get the events flowing, but the frontend needs to act on them
correctly. On a `refresh` event we now refresh every currently-expanded
folder in addition to the root; for multi-repo task roots we scope to
the affected repo's branch using `repository_name`.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix: address iteration-2 review feedback
- Trim doc + inline comment blocks per CLAUDE.md (manager.go,
file-browser-hooks.ts, workspace-files.ts).
- Replace the hand-rolled fmtSscanf/numErr port parser with strconv.Atoi
in the race regression test.
- Assert on slowCalls in the race test to lock in the queue-collapse
guarantee (at most one slow push lands).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix: address iteration-3 review feedback
- Remove redundant stopWorkspaceTrackers call from stopShellAndProcesses
(it's already invoked at the top of Manager.Stop), and drop the now-
misleading "stopping workspace tracker" debug log from the regular
shutdown path.
- Trim three multi-line comment blocks in manager_subscription.go to
one-liners per CLAUDE.md (workspacePushTarget, pushAsync, pushLoop).
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix: trim multi-line comment block on pendingPush field
* fix: trim test docstring on race regression test
* fix(web): preserve sibling-repo subtrees on scoped refresh
The setTree reducer ran patchNode(updated) at the root, which re-matched
folderUpdates.has("") and overwrote the already-merged root children with
the raw depth-1 server response — wiping the loaded children of every
top-level repo that wasn't part of the refresh scope.
Recurse over updated.children instead of updated itself: the root has
already been merged in the block above, and each top-level repo either
gets its targeted update (if folderUpdates.has(path)) or is left alone
(preserving its loaded subtree).
Includes a regression test that fails on the old code: a refresh scoped
to "thm" used to discard "kandev"'s loaded README.md child.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(web): trim three more comment blocks to one-liners
* fix: trim five more comment blocks to one-liners
---------
Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
* fix(agent): honor session passthrough snapshot when starting agent process
Tasks created in agent (ACP) mode got stuck in "starting" after toggling
the profile's cli_passthrough flag and restarting the server.
StartAgentProcess re-resolved the live profile each launch, so the new
flag rerouted existing ACP sessions into the passthrough path (and vice
versa), where the workspace plumbing didn't match.
Snapshot session.IsPassthrough onto LaunchAgentRequest /
lifecycle.LaunchRequest / AgentExecution and let StartAgentProcess use
that as the source of truth. Sessionless launches (legacy
controller.LaunchAgent) still fall back to live profile resolution.
Fixes#981.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(agent): make passthrough snapshot the sole routing signal in StartAgentProcess
Bot review feedback follow-up (#1003):
- Route on the snapshot alone (new routePassthrough helper). A transient
ResolveProfile error no longer silently routes a passthrough session
to ACP — the fresh path surfaces an explicit error, the resume path
surfaces the existing resolvePassthroughAgent error.
- Add TestStartAgentProcess_PassthroughResume_SurvivesProfileResolveError
and TestStartAgentProcess_FreshPassthrough_SurfacesProfileResolveError
to lock the no-silent-ACP-fallback invariant.
- Add TestLaunchPreparedSession_PropagatesIsPassthrough mirroring the
resume-path propagation test so both build paths are independently
covered.
- Strip issue-number references from source/test comments per project
convention.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(agent): avoid double ResolveProfile in sessionless passthrough path
routePassthrough now returns (bool, *AgentProfileInfo). When the
sessionless fallback path already resolved the profile, it threads it
back so StartAgentProcess can reuse it for command building instead of
calling ResolveProfile a second time. Snapshot-driven routing still
returns nil so the snapshot path resolves fresh — the snapshot
deliberately outlives any particular live profile state.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* fix(agent): extract startPassthroughExecution to satisfy nestif
CI's golangci-lint flagged the nested-if complexity of the passthrough
dispatch block in StartAgentProcess after the previous round of fixes
pushed it past nestif's threshold of 5. Move the resume-vs-fresh
branching plus the lazy profile resolution into a startPassthroughExecution
helper so StartAgentProcess becomes a single short routing decision.
No behavior change.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* docs: drop caller reference from startPassthroughExecution comment
Per project convention, source comments shouldn't name the calling
function — the reason it's its own method is captured by its contract
(profileInfo nullability + routePassthrough handoff), not by the
caller's name.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
* fix(lifecycle): publish AgentReady on wakeup-driven turns
Wakeup turns flow Adapter.Prompt → bridge → events, bypassing
SessionManager.SendPrompt. The execution status stayed Ready across
the wakeup turn, so MarkReady's duplicate-suppression guard dropped
the second AgentReady — the orchestrator never closed the turn,
never evaluated on_turn_complete, and never dispatched queued
messages. Detect this in recordActivity and flip Ready → Running on
the first non-terminal event, re-emitting AgentRunning so the rest
of the pipeline behaves like any other turn.
* fix(lifecycle): gate wakeup flip on turn-content events and handle empty turns
Three follow-ups on the wakeup AgentReady fix:
1. Restrict the Ready → Running flip in `recordActivity` to events that
unambiguously indicate turn-in-progress activity (message_chunk,
reasoning, tool_call/update, plan, agent_plan, permission_request).
The original whole-event-type flip caused a regression: claude-agent-acp
emits available_commands_update asynchronously ~50ms after session/new,
well after dispatchInitialPrompt fires MarkBootReady for a no-prompt
task. The Ready → Running flip on that delayed metadata event was
putting newly-created tasks back into Running and breaking the chat-
input UI (changes-panel-focus E2E tests).
2. Handle the empty-wakeup edge case: a wakeup turn that emits only a
`complete` event (empty model response) is still excluded from the
flip whitelist, so the Ready guard in MarkReady would suppress
AgentReady. `handleCompleteEventMarkState` now publishes AgentReady
directly when Status is already Ready on a successful complete —
the orchestrator still closes the turn for empty wakeup responses.
3. Fold the `executionStore != nil` check into the early-return so the
AgentRunning publish only fires when the status flip actually succeeded.
Test-file cleanup from review feedback: dead loop, redundant
`var _ = io.MultiReader`, and `teeReader.src any` → `io.Reader`.
New regression tests:
- TestWakeup_PostBootMetadataEventsDoNotFlipToRunning — locks in the
whitelist behavior so future events can't accidentally re-arm a
boot-ready session.
- TestWakeup_EmptyTurnStillPublishesAgentReady — covers the
empty-wakeup-complete fallback.
* fix(lifecycle): publish AgentRunning before AgentReady on empty wakeup turns
Follow-up on the previous wakeup fixes — addresses three issues raised in
review:
1. **Empty-wakeup AgentReady was ignored by the orchestrator.** The fallback
in `handleCompleteEventMarkState` published AgentReady when Status was
already Ready, but `handleAgentReady` at the orchestrator early-returns
when `session.State != Running/Starting`. After the previous turn ended
the session is in WaitingForInput, so the AgentReady got silently
dropped — same suppression the wakeup fix was meant to prevent. Now the
fallback flips Ready → Running + publishes AgentRunning first (mirroring
`recordActivity` for the non-empty case), then falls through to MarkReady.
2. **firstActivityOnce could still publish AgentRunning on a late
metadata event.** Gate it on `Status != Ready` so a delayed
`available_commands_update` arriving after MarkBootReady (the original
regression scenario) can't slip through via the once-per-execution path.
In practice the adapter always emits `agent_capabilities` during
Initialize before MarkBootReady, so firstActivityOnce still fires there
with Status==Running — this is defensive hardening.
3. **Tighter test assertions.** The post-boot-metadata test now primes
firstActivityOnce in setup and asserts strict `runningCount == 0`.
The second-turn test verifies AgentRunning precedes each AgentReady in
bus order so the orchestrator's session-state guard isn't violated.
Same ordering check added to the empty-wakeup test.
* test(lifecycle): rename exec to agentExec to avoid os/exec shadow
The test variable `exec` in wakeup_e2e_test.go shadowed the imported
`os/exec` package — harmless today because all `exec.Command`/`LookPath`
calls happen before the local binding, but a future call added below
would silently fail. Rename to `agentExec` to remove the shadow.
* ci: retrigger CodeQL after transient Ruby analyze flake
The default-setup CodeQL run on PR #875 produced a flaky 'CodeQL could
not process any code written in Ruby' failure on the Ruby analyze job
(github.com/kdlbs/kandev/actions/runs/26124163769). The repo has no
Ruby code and main's CodeQL only analyzes javascript-typescript +
actions; the Ruby job was added dynamically and failed on the empty
diff. Sibling run 26124163815 on the same SHA passed. Cannot rerun
default-setup workflows via the API (403 'cannot be retried'), so
push an empty commit to retrigger the analysis.
* test(lifecycle): tighten wakeup test assertions
- wakeup_simulated_test.go: assert exact readyCount==2 instead of <2 so
any over-emission (e.g. duplicate AgentReady on the wakeup turn) is
also caught.
- wakeup_e2e_test.go: fail with t.Fatalf when the adapter surfaces no
WAKEUP text instead of logging a warning. Otherwise the bus-level
assertions below pass vacuously if the wakeup never fires.
Both fixes address review comments from cubic-dev-ai / claude[bot] on
PR #875.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
* test(lifecycle): remove unsynchronised SessionID write in forwarder goroutine
The forwarding goroutine wrote to agentExec.SessionID without holding
the executionStore mutex, racing with the main goroutine's authoritative
assignment after NewSession returns. The forwarder's write is redundant
— line 264 sets the canonical value — and benign in practice, but
`go test -race` would flag it. Drop the write to keep the race detector
clean.
Addresses review comment from claude[bot] on PR #875.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
---------
Co-authored-by: Kandev Agent <agent@kandev.dev>
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>