Skip to content

fix(platform): serve the automation run's workspace tools - #3126

Merged
larryro merged 2 commits into
mainfrom
fix-sandbox-workflow-run-tool-lane
Sep 1, 2026
Merged

larryro merged 2 commits into
mainfrom
fix-sandbox-workflow-run-tool-lane

Conversation

@larryro

@larryro larryro commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An automation agent on demo05 could not use a single one of its granted workspace tools: ask_human threw [ctx-shim] un-shimmed mutation call: automations/human_asks:createAskForExec (DEMO05TALEDEV-4) and every task/knowledge tool refused with no_access_context, so a run could neither file work nor escalate a question. Both are the same unfinished lane — the 0.5 port left the workflow_run binding resolver answering none and the ask handler out of the sandbox map "until the automations engine ports", and the engine started minting those sessions in v0.5.5/0.5.6. Seven more handler names the reused bridge reaches were in no map at all, so every write tool would have thrown the same way once the access gate opened.

What changed

  • Binding resolution (domains/sandbox/shim.ts) carries 0.4's sessionBinding whole: ${runId}:<suffix> splits back to the run; a run pinned to a project acts there, one without acts org-wide across its automation's bindings, and writes are attributed to automation:<name>. Bindings are read unjoined — an empty set means unbounded, so a join that dropped a row would widen authority.
  • The write lane (sandbox/workspace-write-shim.ts, documents/agent-write.ts) answers the seven missing names by reusing the service functions the human and connector lanes already call. document_create's blob → upsert-by-external-id → link → RAG chain becomes one reusable pair instead of a fourth divergent copy.
  • The ask handler moves verbatim into automations/ask-shim.ts, a leaf both maps spread — the sandbox map may not import the automations map, which is already spread the other way round.
  • agentUpdateTaskStatusTrusted answers a refusal CODE, not prose: the bridge branches on AGENTS_CANNOT_COMPLETE to tell an agent to park at in_review. The connector native renders the codes back into sentences for the operator reading a failed run.

Why nothing caught it

The dispatch route's probe used a project_agent session; the ask lane's probe called the handler map directly. Each half green, the real chain never run. Two guards close that class:

  • domains/sandbox/shim.test.ts walks the bridge's own import graph and fails on any reachable internal.x.y.z the map cannot answer. Mutation-checked: removing the ask spread turns it red and names createAskForExec.
  • The integration suite drives a real workflow_run session through POST /api/tools/execute for both bindings.

The completion gate, re-read against its own contract

Second commit. agentUpdateTaskStatusTrusted refused every terminal status for every actor; 0.4 refused only done. The port compressed status === 'done' && actorId !== 'workflow' into TERMINAL_STATUSES.has(status) and swallowed cancelled with it.

  • cancelled is restored — abandoning a card is not certifying it, and the automation lane had always been allowed to do it. It comes back with the human writer's open-subtasks guard (which the blanket refusal had made unreachable: the bridge branches on TASK_HAS_OPEN_SUBTASKS and could never receive it) and its completed_at_ms stamp, so both lanes agree on what a closed card looks like.
  • done stays refused for every actor — configs/platform/system/connectors/task/connector.yml has said since feat(platform): rewrite the AI backend on a minimal YAML-config core #2857 that completion is the human review gate's. 0.4's workflow exemption was the half that disagreed with its own catalog, so this is not a behaviour change; it is the contract winning.
  • The node offers only what it can honour. done leaves the action's enum in the catalog and in the native's zod input, so a literal status: done now fails at authoring with CONNECTOR_INPUT_INVALID (the deploy-time contract check compiles that schema) instead of failing every single time the run reaches the node. A templated status still resolves at dispatch, where Ajv now names the values that would have worked — it says "must be equal to one of the allowed values" and then does not say which.

The agent-facing task_update_status tool keeps done in its vocabulary on purpose: a model learns from the structured refusal and its "park at in_review" guidance, whereas a human authoring a node should never be offered an option that cannot work.

Checklist

  • bun run check passes (format, lint, typecheck, all tests) — 40/40 tasks.
  • bun run lint:sast passes (Opengrep) — 0 findings.
  • N/A — translations: the only new strings are connector-error and agent-facing English, the existing convention for this lane (no messages/ key added).
  • N/A — docs: no user-visible surface changes; this restores documented behaviour. The backend/MIGRATION.md sandbox row, which asserted the old placeholders, is updated in this change.
  • N/A — READMEs: no env var, flag, or command changed.

Test plan

bun run check
bun run --filter @tale/platform test -- backend/domains/sandbox/shim.test.ts

docker run --rm -d --name tale-backend-itest -e POSTGRES_PASSWORD=itest \
  -p 54329:5432 ghcr.io/tale-project/tale/tale-db:latest
docker run --rm -d --name tale-itest-minio -p 59002:9000 \
  -e MINIO_ROOT_USER=minioadmin -e MINIO_ROOT_PASSWORD=minioadmin \
  minio/minio:latest server /data
until docker exec tale-backend-itest test -f /tmp/.db_ready; do sleep 1; done
DATABASE_URL=postgres://tale:[email protected]:54329/tale \
  ITEST_S3_ENDPOINT=http://127.0.0.1:59002 TALE_CONFIG_DIR=$(mktemp -d) \
  bun run --filter @tale/platform backend:integration

Observed 277/277 integration checks, including the new automation-run tool lane (workflow_run session through /api/tools/execute) — which now also covers cancelling over an open child (refused), the child cancelling, the parent following with a completion stamp, and done staying unavailable. On demo05 after deploy: an automation agent's ask_human should register the question against its run instead of 500-ing, and task_create should land a card on the run's project board.

An automation agent on demo05 could not use a single one of its granted
workspace tools. `ask_human` threw `[ctx-shim] un-shimmed mutation call:
automations/human_asks:createAskForExec` (GlitchTip DEMO05TALEDEV-4) and
every task/knowledge tool refused with `no_access_context` — so a run
could neither file work nor escalate a question.

Both are the same unfinished lane. The 0.5 port left two placeholders in
`domains/sandbox/shim.ts`: the binding resolver answered `none` for a
`workflow_run` session "until the automations engine ports", and the ask
handler was "deliberately NOT in this map" for the same reason. The
engine started minting those sessions in v0.5.5/0.5.6; the placeholders
never came out.

Seven more handler names the reused bridge reaches were in no map at all,
so every write tool would have thrown the same way once the access gate
opened: listTasksForAgent, agentCreateTask, agentUpdateTaskStatus,
agentUpsertTaskByExternalRef, and document_create's storeRawContent /
upsertDocumentByExternalId / linkDocumentToFile.

- The binding resolver carries 0.4's `sessionBinding` whole: `${runId}:…`
  splits back to the run; a run pinned to a project acts there, one
  without acts org-wide across its automation's bindings, and writes are
  attributed to `automation:<name>`. Bindings are read UNJOINED — an
  empty set means unbounded, so a join that dropped a row would widen
  authority rather than narrow it.
- The write lane (`sandbox/workspace-write-shim.ts`) and the document
  chain (`documents/agent-write.ts`) reuse the service functions the
  human and connector lanes already call; `document_create`'s blob →
  upsert-by-external-id → link → RAG chain becomes one reusable pair
  instead of a fourth divergent copy.
- The ask handler moves verbatim into `automations/ask-shim.ts`, a leaf
  both maps spread, because the sandbox map may not import the
  automations map (it is already spread the other way round).
- `agentUpdateTaskStatusTrusted` answers a refusal CODE, not prose: the
  bridge branches on `AGENTS_CANNOT_COMPLETE` to tell an agent to park at
  `in_review`. The connector native renders the codes back into sentences
  for the operator reading a failed run.

WHY NOTHING CAUGHT IT: the dispatch route's probe used a `project_agent`
session and the ask lane's probe called the handler map directly. Each
half green, the real chain never run. `domains/sandbox/shim.test.ts` now
walks the bridge's own import graph and fails on any reachable
`internal.x.y.z` the map cannot answer, and the integration suite drives
a real `workflow_run` session through `POST /api/tools/execute` for both
bindings — ask, create, find, the refused `done`, an out-of-reach card,
the idempotent external-ref sync, and both document scopes.

Integration 277/277 on a throwaway Postgres + MinIO.
`agentUpdateTaskStatusTrusted` refused EVERY terminal status for every
actor. 0.4 refused only `done`, so the port's compression of
`status === 'done' && actorId !== 'workflow'` into
`TERMINAL_STATUSES.has(status)` swallowed `cancelled` with it — and an
automation deciding "this ticket is obsolete, close the card" is a
different act from certifying finished work.

- `cancelled` is restored, with the human writer's open-subtasks guard
  (which the blanket refusal had made unreachable — the bridge branches
  on `TASK_HAS_OPEN_SUBTASKS` and could never receive it) and its
  `completed_at_ms` stamp, so the two lanes agree on what a closed card
  looks like.
- `done` stays refused for every actor. The shipped catalog entry has
  said since #2857 that completion is the human review gate's; 0.4's
  `workflow` exemption was the half that disagreed with its own contract.

The node now offers only what it can honour. `done` leaves the action's
enum in `configs/platform/system/connectors/task/connector.yml` and the
native's zod input, so a literal `status: done` fails at AUTHORING with
`CONNECTOR_INPUT_INVALID` — the deploy-time contract check compiles that
schema — instead of failing every single time the run reaches the node.
A templated status still resolves at dispatch, where Ajv now NAMES the
values that would have worked: it says "must be equal to one of the
allowed values" and then does not say which, which leaves the caller
with the one question they actually have.

Integration 277/277: cancelling over an open child is refused, the child
then cancels, the parent follows and lands `cancelled` with a completion
stamp, and `done` stays unavailable. The natives suite covers the
contract-level `done` refusal, the allowed `cancelled`, and the operator
sentence a refusal code renders as.
@larryro
larryro merged commit 9f50b6c into main Sep 1, 2026
48 checks passed
@larryro
larryro deleted the fix-sandbox-workflow-run-tool-lane branch September 1, 2026 06:18
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