Skip to content

fix(platform): fix MCP live runs and prune dead agent and skill paths - #3256

Merged
larryro merged 9 commits into
mainfrom
fix/skills-agents-builder-hardening
Sep 6, 2026
Merged

larryro merged 9 commits into
mainfrom
fix/skills-agents-builder-hardening

Conversation

@larryro

@larryro larryro commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes for the builder-skills-agents theme of the backend fix campaign (Automations builder, skills, agents). Seven commits on fix/skills-agents-builder-hardening; no migration.

Findings fixed

  • builder-skills-agents-1 (= automations-domain-5, lib-engine-1) — run_deployed / run_automation {mode:"live"} ran the deterministic mocks yet persisted a mode='live' success + audit row for any membership-only key; a live run_deployed now goes through the durable runner (startRun, developer-authorized, bounded 30 s wait, run handle when it outlives the wait), run_automation {mode:"live"} is refused as data; tool descriptions + en/de/fr MCP docs updated; itest lane extended (6bc72587d).
  • builder-skills-agents-2 — builder session host never forwarded isCancelled; POST /automations/builder/sessions now passes the request abort signal so an abandoned request ends cancelled at its next turn boundary (5eb465874).
  • builder-skills-agents-3 — dead GET /:slug/resolved, GET /:slug/history, POST /:slug/restore + lib/agents/resolve.ts, history readers, ResolvedAgentView, the importer-less app/features/agents/hooks/queries.ts, the agents/actions:listAgentHistory + chat/capabilities_action:listCapabilities contract rows/adapter, configKeys.history; docs en/de/fr History bullet reworded (trail stays on disk, no restore door); itest lane trimmed to save/list/edit/delete (50d07178e).
  • builder-skills-agents-4 — seven retired Auto-router constants deleted, SUPPORTED_AGENT_LOCALES kept; the now-obsolete knip ignore entry dropped (000aa1369, 2c138bd39).
  • builder-skills-agents-5 — skills.upload_mutations.deleteSkillUploadIntent handler-name declaration with no shim handler removed (000aa1369).
  • builder-skills-agents-6 — test-only filterVisibleSkills removed (000aa1369).
  • builder-skills-agents-7 — test-only hasInteriorWhitespace removed (000aa1369).
  • builder-skills-agents-9 — upsertAgentSecret is one INSERT … ON CONFLICT (org_id, name) DO UPDATE … RETURNING (xmax = 0) AS created under a per-org advisory xact lock; the cap counts only the other names (a full org can still rotate); regression test with a scripted sql (a9e783321).
  • builder-skills-agents-10 — the skill bundle upload's replace decision (existing bundle, edit rights, owner) now runs inside withSkillWriterLock, blob cleanup in finally; regression test runs two concurrent uploads of one new slug through a serializing begin and expects one write + one needs_confirm (fc18f5901).

Skipped

(none)

Tests & gates observed

  • bunx tsc --noEmit → exit 0
  • bunx oxlint --type-aware → exit 0 (no output)
  • bun run check (worktree root) → Tasks: 40 successful, 40 total — @tale/platform:lint: Found 0 warnings and 0 errors.; @tale/platform:test:ui: Test Files 456 passed (456) / Tests 3512 passed (3512); @tale/shared:test: Test Files 22 passed (22)
  • bun run knip:check → exit 0 (remaining hint cron-parser … Remove from ignoreDependencies is pre-existing on main)
  • Targeted server suites: backend/core/agents backend/domains/agents lib/agents → 4 files / 61 tests passed; backend/domains/agent_secrets backend/domains/skills backend/core/skills → 7 files / 90 tests passed
  • Integration proof (run-itest.sh): [itest] 475/476 checks passed across 134/134 lanes — the one FAIL is webdav re-home (protocol + tree + locks + visibility on pg), the pre-existing red lane on main (webdav theme). Theme lanes: PASS agents file layer (save/list/edit/delete), PASS blob-ref authority: skill upload consumes its own intent…, PASS platform MCP endpoint (/api/v1/mcp) — … runDeployed=live/success/row=true, memberLive=refused/noRun=true …, PASS automation builder session (scripted model, pg store).

Notes for the reviewer

  • No migration in this PR (0084 left free).
  • The finding-3 commit header was re-worded (81 → 68 chars) with one git push --force-with-lease of my own just-pushed tip, minutes after the first push; no other history rewrite.
  • Finding 3 keeps the agents/actions:listAgents / getAgent contract rows and the /api/app/agents list/get/put/delete routes: they are the app door the itest and REST v1 parity rely on; only the doors with no reachable caller were removed. The on-disk .history/ trail every save writes is untouched.
  • Finding 9: RETURNING (xmax = 0) AS created is the standard insert-vs-update tell for ON CONFLICT DO UPDATE; the fake-sql test pins the statement shape, the real-Postgres itest exercises the door.
  • Branch merges cleanly onto origin/main (3997f6a) per git merge-tree.

`run_deployed` and `run_automation {mode: "live"}` on the MCP endpoint and
the chat capability lane enabled live execution (`allowLive: true`) but the
engine has no in-process live path: `lib/connectors/registry.ts` attaches
only a `mock` body to every engine connector and no host ever supplied a
`connectorHost`, so `execute()` always ran the deterministic mocks — and
`recordRun` then persisted the outcome as a mode='live' success with a
provenance audit row, for any membership-only key (no developer gate).

`DispatchContext` now carries `connectorHost`; without one a live
`run_deployed` is handed to the store's durable runner (`startRun`, the
same lane `start_run` uses — the stepper authorizes the actor as developer,
executes connectors live and records the run) and waits a bounded 30 s for
the finished result, answering with the run handle when the run outlives
the wait. `run_automation {mode: "live"}` — an unsaved document, which no
durable runner can take — is refused as data and pointed at run_deployed.
Tool descriptions, the agent guide and the en/de/fr MCP endpoint docs say
so; the integration lane proves run_deployed live settles through the
stepper and a member key is refused before any run row is born.

Finding: builder-skills-agents-1 (= automations-domain-5, lib-engine-1).
The builder session host (`runSessionWithStore`) never forwarded the
lib's `isCancelled` seam, so the `cancelled` outcome its type advertises
was unreachable in production: a reload, a closed tab or a dropped
connection left the server looping model calls (and possibly saving
versions nobody would read) until the 7-minute deadline or the turn cap.

`BuilderSessionArgs` gains `isCancelled`, forwarded to
`runBuilderSession`; POST /automations/builder/sessions passes the
request's abort signal, so the session ends `cancelled` at its next turn
boundary once the caller is gone.

Finding: builder-skills-agents-2.
`GET /api/app/agents/:slug/resolved`, `GET /:slug/history` and
`POST /:slug/restore` had no caller from any door a user or integrator can
reach: the app hooks that named them (`useAgents`/`useAgent`/
`useAgentHistory`/`useCapabilityCatalog` in `app/features/agents/hooks/
queries.ts`) were imported by nothing — MIGRATION.md inc 123 already
recorded the file as importer-less — the REST v1 family exposes only
list/get/put/delete, and `lib/agents/resolve.ts` (the tools/skills
allowlist predicates) was consumed by no chat, task or automation host.
Only the integration check exercised them, so the documented "restore"
rule described a feature nobody could use.

Removed: the three routes and their `*ForCaller` functions, the resolve
module and its test, the history readers (`listAgentHistoryEntries`,
`readAgentHistoryText`, `AgentHistoryEntry`), `ResolvedAgentView`, the
`AGENT_HISTORY_ENTRY_NOT_FOUND` status row, the dead hooks file, the
`agents/actions:listAgentHistory` and `chat/capabilities_action:
listCapabilities` contract rows with their adapter, and `configKeys.
history`. The on-disk history trail every save writes is untouched; the
en/de/fr admin docs now say an operator reaches it on disk and that the
API offers no restore. The integration lane proves save/list/edit/delete.

Finding: builder-skills-agents-3.
@larryro
larryro force-pushed the fix/skills-agents-builder-hardening branch from 86f30ab to 50d0717 Compare September 5, 2026 22:19
Four exports survived their last consumer and misled readers about
behaviour that no longer exists:

- `lib/shared/constants/agents.ts` carried seven retired Auto-router
  constants (`AUTO_AGENT_SLUG`, `ROUTER_AGENT_SLUG`, `RESERVED_AGENT_SLUGS`,
  `PROTECTED_AGENT_NAMES`, `DEFAULT_CHAT_AGENT_SLUG`, the conversation
  starter caps) whose comments promised a reserved-slug check `saveAgent`
  never performs; only `SUPPORTED_AGENT_LOCALES` has consumers and stays.
- `handler_names.ts` declared `skills.upload_mutations.deleteSkillUploadIntent`
  with no shim handler and no caller — a call would have thrown as
  un-shimmed; the reachability gate only checks referenced names.
- `lib/skills/visibility.ts#filterVisibleSkills` and
  `core/agent_secrets/constants.ts#hasInteriorWhitespace` (whose docstring
  described an editor warning no code delivers) were used only by their own
  tests.

Knip is blind to all four because `backend/**` entries keep the modules
reachable; the type-check is the guard.

Findings: builder-skills-agents-4, -5, -6, -7.
`upsertAgentSecret` was check-then-act inside its transaction: SELECT the
row (no lock), then UPDATE or count-and-INSERT. Two concurrent first saves
of one name — a double submit, a retry, two admins — both passed the SELECT,
the loser hit UNIQUE (org_id, name) and its PostgresError 23505 fell through
`handleError` to the global handler as a reported 500; two creates at
cap-1 both passed the count, so the per-org cap was soft.

The write is now ONE `INSERT … ON CONFLICT (org_id, name) DO UPDATE …
RETURNING (xmax = 0) AS created`, so racing saves converge on one row and
the caller learns which outcome landed; the cap check runs under a
per-org advisory xact lock and counts only the OTHER names, so a full
org can still rotate a secret it already holds. The audit action follows
the row that landed.

Finding: builder-skills-agents-9.
The bundle-upload lane read the existing skill, computed `bundleExists`,
checked edit rights and derived the owner BEFORE taking the per-(org, slug)
writer lock, and only the final write ran inside it — unlike the editor's
save, whose checks run under the same lock. Two members uploading the same
new slug both observed "no bundle": neither got `needs_confirm`, the second
write replaced the first and rewrote its owner — exactly the silent
replacement the needs_confirm/force protocol exists to prevent.

The whole decision now runs inside `withSkillWriterLock` (the lock is held
for a directory read and a rename, so a refusal holds it for nothing); the
staged blob is released in a `finally` on every path, and only the write
itself is still mapped to WRITE_FAILED. The regression test runs two
concurrent uploads of one new slug through a serializing `begin` and
expects one write and one `needs_confirm`.

Finding: builder-skills-agents-10.
…need

With the seven retired Auto-router constants gone, every remaining export
of `lib/shared/constants/agents.ts` has a consumer, and knip reports the
ignore entry as obsolete. Removing it lets knip watch the file again.

Finding: builder-skills-agents-4 (sweep).
@larryro
larryro marked this pull request as ready for review September 5, 2026 22:28
@larryro
larryro merged commit 5d31738 into main Sep 6, 2026
48 checks passed
@larryro
larryro deleted the fix/skills-agents-builder-hardening branch September 6, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant