Commit Graph
18 Commits
Author SHA1 Message Date
sam 59cc831ff7 feat(tools): add per-server parallel_tool_calls to the MCP client
MCPServer gains ParallelToolCalls (default false). The client's
per-server callMu is now nil for a server that opted in, so CallTool
stops serializing that server's calls and the caller's own concurrency
decides; every other server keeps exactly one tools/call in flight.

The flag is threaded from config through the provider constructor -
the only place MCPServer configs become Client instances - into
NewClient, in both the daemon and the agent worker.
2026-09-22 01:57:58 +10:00
sam 7ac7a3df6b fix(mcp): cancel in-flight SSE reconnect on Stop
WIRE: the SSE transport's Stop contract already says it closes the
connection and waits for background readers, but the reconnect loop issued
its HTTP GET with the Start context, which Stop could not cancel, so Stop
blocked on readerWg.Wait() against an unreachable endpoint. Wire a
per-lifecycle cancel (mirroring the stdio transport's stopCh plus guarded
commit) so Stop interrupts the in-flight reconnect request.
2026-09-15 13:30:29 +10:00
sam fe66f40b2b refactor(tools/mcp): delete unreachable MCP adaptation path
DELETE: mcp.Client.RegisterTools and its handlerFor/writeMultimodalResult
chain, plus the WithMediaDir and WithParallelToolCalls options, had no
production caller -- the live adaptation path is provider/mcp.Provider,
which now owns binary media persistence itself. A repo-wide search finds
no remaining reference outside the composition contract test that asserts
RegisterTools must not appear, so the two paths can no longer diverge.
2026-09-15 12:58:10 +10:00
sam 95342037b0 test: replace brittle assertions with behavior checks
- mcp client_test: assert both initialize handshake calls happened and
  notifications/initialized has an empty ID, not their exact order
- telegram model_test: assert the resolved model has an openrouter/
  prefix instead of scanning button text for the string; replace the
  single-hardcoded-count pagination test with cases covering 0/1/8/9/100
  models so pageBounds and nav-row logic are actually exercised
- webui api_chat_test: assert the actionable file path is present in the
  streamed error instead of matching generic wording
2026-09-01 23:39:23 +10:00
sam 1c975b8348 fix(container): persist npm cache for per-task MCP servers
Ephemeral task containers re-resolve and re-download npx-launched MCP
server packages from the npm registry on every task, since each task
gets a fresh container with no persistent cache -- a worse amplifier
of a registry outage than the daemon-restart case d4bb914b already
fixed.

Extract the daemon's npm-cache env logic into mcp.NpmCacheEnv, shared
by both the daemon's own long-lived npx MCP servers and archie-agent's
per-task ones. Mount a new archie-cache-mcp-npm Docker volume at
/data/cache/mcp-npm on every task container regardless of ecosystem
(MCP servers are daemon-wide config, not tied to the task repo's
language), and point npx-launched per-task stdio transports at it.

Closes archie-core-qk8m.
2026-08-22 21:13:33 +10:00
sam d3dd06d48f Merge remote-tracking branch 'origin/feat/75-add-mcp-client-capabilities-to-archied-and-archie-agent'
# Conflicts:
#	cmd/archie-agent/main.go
#	cmd/archied/main.go
#	cmd/archied/main_test.go
#	internal/agentexec/nats.go
#	internal/config/config.go
#	internal/tools/budget_test.go
#	internal/tools/dispatch_test.go
#	internal/tools/mcp/transport_sse.go
2026-07-29 23:19:36 +10:00
sam a9e8cda4f2 fix(qa4.3): resolve nilerr, bodyclose, contextcheck, containedctx, fatcontext lint findings
- bodyclose: add deferred resp.Body.Close() in storage_test.go Docker test handler
- contextcheck: thread context through email handleSMTP/processMessage; replace
  context.Background() with context.WithoutCancel(ctx) in telegram, webhook, webui
  shutdown paths and container pool cleanup; add ctx parameter to Pool.Release
- containedctx: replace ctx context.Context struct field with stopCh chan struct{}
  in StdioTransport and SSETransport; thread lifecycle context through goroutine
  chains instead of storing it in structs
- fatcontext: lift context deadline derivation out of PrefetchContext loop
2026-07-29 10:10:42 +10:00
sam 4ee8579ddc refactor: phase 2 of lint remediation — mechanical fixes (qa4)
130 -> 96. forcetypeassert, predeclared and usetesting are now at zero.

Fanned out across four isolated worktrees partitioned by package so no
two workers could touch the same file: internal/tools (20 assertions),
internal/webui, internal/memory + internal/ratelimit, internal/secret.
Four stragglers outside those scopes fixed inline (internal/pairing,
internal/forge, internal/channels/telegram, internal/tools/mcp).

Unchecked type assertions became comma-ok with a t.Fatalf naming the
actual type. One site in a goroutine uses t.Errorf + return instead,
since t.Fatalf from a non-test goroutine is undefined behaviour.

predeclared renames chose names from meaning rather than adding a
suffix: max -> maxQueryLen, maxMatchLen, maxRequests, alphabetLen, and
nextBackoff's max -> ceiling. `real` -> `base` in the webui tests.

os.Setenv became t.Setenv, which restores on cleanup, so the paired
deferred Unsetenv calls went with it.

Note for future fan-outs: the agent worktrees branched from origin/main
(a7388a0), not from this branch, so every diff arrived based on a tree
without the phase 1 autofix. They were applied with `git apply --3way`
and the phase 1 changes to internal/memory/manager.go were verified to
survive — in particular the repaired `ctx, cancel =` assignment. A plain
`git apply` would have silently reverted it.
2026-07-28 01:37:20 +10:00
sam 15d746c2f6 style: phase 1 of lint remediation — autofix pass (qa4)
golangci-lint run --fix plus the formatters: errorlint, gocritic,
sloglint, usestdlibvars, usetesting, gci, gofumpt, goimports.
160 issues -> 130.

One autofix was wrong and had to be reverted by hand. gocritic rewrote

    ctx, cancel = context.WithTimeout(ctx, m.prefetchTimeout)

to `:=` inside an if-block in internal/memory/manager.go. That does not
compile, which is the good outcome — had it compiled, the shadowed ctx
would have scoped the timeout to the if-block and the prefetch deadline
would silently never have applied. Restored the assignment and commented
why it must not be a declaration.

Worth recording: --fix is not a safe no-op. It broke the build on a
24-file change, and the failure mode it was one compiler error away from
was a silent behaviour change.
2026-07-28 01:37:20 +10:00
sam ec8534dfe2 feat(gateway): ship model controls, shell tools, and release tracking 2026-07-27 06:16:39 +10:00
archie 5f964030c5 feat: add MCP client capabilities to archied and archie-agent (archie)
Implements #75
2026-07-26 19:51:36 +00:00
sam b9ecf37a48 refactor: replace fmt.Sprintf with fmt.Appendf in test 2026-07-27 04:03:23 +10:00
sam 6fe1a7d037 fix: lint cleanup across repo (errcheck, staticcheck, ineffassign, unused)
- daemon.go: real bug — maybeRetryParked resolved fg := d.forgeFor(task)
  (matching markDead's pattern) but called d.Forge.SetStateLabel instead
  of fg.SetStateLabel, silently using the wrong forge client for
  multi-identity/multi-forge task routing. Fixed to use fg throughout.
- telegram.go: updateThreadID existed but was never called anywhere;
  wired it into updateLoggingMiddleware so debug logs include thread_id.
- Two SA9003 empty-branch tests (nell adapter_test.go, tools
  toolentry_test.go) were dead assertions with no body; implemented the
  actual check instead of deleting them.
- memory manager_test.go: mockProvider.lastConfigSchema/lastBackupPaths
  were declared but never recorded; wired GetConfigSchema/BackupPaths to
  populate them and strengthened the aggregation tests to assert on
  per-provider content, not just counts.
- Removed genuinely dead gateway messageevent_test.go helpers (intPtr/
  i64Ptr, marked //go:fix inline, already fully superseded by the new()
  builtin used throughout the file).
- Remaining errcheck findings (defer Close/Flush/Write, os.Setenv, etc.
  in test files) fixed with the existing `_ = ` convention already used
  elsewhere in the codebase.

go build ./..., go test ./... (all packages ok), and
golangci-lint run ./... all clean.
2026-07-27 03:49:33 +10:00
sam 97e6a54da5 fix: MCP stdio transport lifecycle races and dead SendTimeout config
Implement the SendTimeout config field (previously silently ignored) via a
timeout-bounded write helper, and close two related races found during
adversarial review: Start()/Stop() could interleave across separate lock
acquisitions, and a subprocess spawned by a fresh Start() or a
crash-triggered restart could clobber a StateStopped already committed and
reported by a concurrent Stop(). Both spawn-commit paths now funnel through
a single guarded commitSpawnedProcess. Closes archie-core-abg.17.16,
archie-core-abg.17.23, archie-core-abg.17.41.
2026-07-27 03:46:47 +10:00
sam f73b2d1c8c feat: memory manager sync/prefetch/scan/shutdown + broad in-flight epic work
Checkpoint commit covering concurrent work across several archie-core-abg
epics to avoid losing in-progress state:

- Memory manager (18.7-18.16): background sync pipeline, prefetch with
  timeout, memory-write notification, threat scanning, shutdown drain
  with abandoned-write tracking, frozen snapshot pattern. Wired
  ScanContent and NotifyMemoryToolWrite into HandleToolCall so scanning
  and notification actually apply to writes, not just exist as unused
  primitives.
- Fixed a literal unresolved merge-conflict that had been committed to
  internal/memory/scrubber/scrubber.go.
- Tool provider/registry, MCP client/transport (stdio, HTTP, SSE),
  multimodal results, disclosure.
- Pairing device auth store, rate limiting.
- Gateway compression, session store, tasks.
- Various workflow, plugin host, and agentexec updates.
2026-07-27 03:34:46 +10:00
sam f6d51416f0 chore: replace 607 em-dashes with double hyphens project-wide
Includes MCP crash-after-init test fix (crash moved from handle() to serve()
entry point so transport sees immediate subprocess death).
2026-07-26 09:53:33 +10:00
sam 0746950cb7 fix: MCP transport framing + crash retry + test harness (17.16)
framing.go: documented that readMessage caller must manage the
bufio.Reader lifetime. Creating a new bufio.Reader per call silently
drops buffered data and breaks multi-message streams.

transport.go: added crashCount check alongside startupFailures for
the MaxRetries limit — crash-looping subprocesses (spawn succeeds
but process immediately dies) now count toward the retry cap.

transport_test.go: replaced os.Exit(1) with syscall.Exit(1) in
crash-after-init behavior — Go's test harness intercepts os.Exit
and panics instead of exiting, keeping the process and its pipes
alive indefinitely. Replaced os.Exit(0) with runtime.Goexit() in
TestMCPServerHelper for clean goroutine exit.

Framing multiple-message test passes. Crash retry tests may need
further debugging in the transport spawn/reader lifecycle.
2026-07-26 01:57:41 +10:00
sam 3b9c280b12 wip: MCP transport types + framing + tests (17.16 partial)
Deepseek workflow ran before hitting session limit. Delivered:
  types.go — TransportState enum, JSON-RPC 2.0 Request/Response/Error
  framing.go — Content-Length header framing (LSP-compatible, 4MB max)
  transport_test.go — 585 lines of tests (red: implementation missing)

Memory verification fixes also included (lifecycle, manager, test updates).

transport.go still needed — the main MCPServer Connect/Disconnect
implementation. Tests are written, implementation is ~200 lines.
2026-07-26 01:40:05 +10:00