Skip to content

fix(workflow): authenticate integration calls from tenantless tool steps and throw on refusal - #5571

Open
mattboon wants to merge 9 commits into
veryfront:mainfrom
mattboon:mattboon/fix-remote-tool-auth
Open

mattboon wants to merge 9 commits into
veryfront:mainfrom
mattboon:mattboon/fix-remote-tool-auth

Conversation

@mattboon

@mattboon mattboon commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

veryfront/veryfront-issue-inbox#4462 (code half). A workflow tool() step that calls runRemoteIntegrationTool("salesforce__list_cases", args, context) under a local veryfront workflow run <id> returns {"error":"no_api_token"}, even with VERYFRONT_API_TOKEN set or after veryfront login. The same call from a plain script works.

Root cause: StepExecutor.executeTool (src/workflow/executor/step-executor.ts) always built the tool context with authToken: tenant?.token. A local run has no tenant, so the context carried an own authToken: undefined. runRemoteIntegrationTool reads an own authToken as "the caller owns the credential" (on purpose, see does not fall back when the hosted resolver owns an absent credential in remote-tools.test.ts), so it never fell back to the environment or login token.

The call also returned the error object instead of throwing, so a step that reads .data saw no rows and the run completed with nothing done.

Change

  • StepExecutor.executeTool sets the tenant fields (authToken, projectSlug, projectId, release, branch, environment) only when the run has a tenant. A tenantless run now resolves the token the same way a plain script does: VERYFRONT_API_TOKEN, then the veryfront login token. Tenant runs are unchanged.
  • Workflow tool steps mark their context with workflowStep: true (new optional ToolExecutionContext field). With that marker, runRemoteIntegrationTool throws a VeryfrontError (integration-tool-call-refused) instead of returning an error object when:
    • the API answers non-2xx: Salesforce refused list_cases for this workflow run: <API message>
    • the integration returns an MCP tool error: Salesforce refused list_cases for this workflow run: <tool message>
    • no token is available: Salesforce list_cases did not run for this workflow run: no Veryfront API token. Set VERYFRONT_API_TOKEN or run `veryfront login`.
  • Agent tool calls have no marker and still get the error object, so the model can read it.
  • integrationDisplayName in src/integrations/unconnected.ts is exported and reused for the integration name.
  • CHANGELOG: breaking entry for the throw.

The hosted 403 (authorization-denied, "Insufficient permissions to use this integration tool") is the API's half and is not changed here. One thing to check on the API side: a workflow tool step sends agent_id: "workflow" and no run_id in the /integration-tools/<name>/run body, so the API cannot tie the call to the workflow run.

Validation

New tests in src/workflow/executor/step-executor.test.ts (StepExecutor integration tool calls), each running a real tool() step that calls runRemoteIntegrationTool against a mocked API.

Red, the new tests on main:

StepExecutor integration tool calls ...
  authenticates a tenantless run with the environment token ... FAILED
    -   null
    +   "Bearer env-token"
  authenticates a tenant run with the tenant token ... ok
  fails the step with the reason when the API refuses the call ... FAILED
  fails the step with the reason when the integration returns a tool error ... FAILED
  fails the step when no API token is available ... FAILED
FAILED | 0 passed (1 step) | 1 failed (4 steps) | 9 filtered out

Green, with this change:

StepExecutor integration tool calls ...
  authenticates a tenantless run with the environment token ... ok
  authenticates a tenant run with the tenant token ... ok
  fails the step with the reason when the API refuses the call ... ok
  fails the step with the reason when the integration returns a tool error ... ok
  fails the step when no API token is available ... ok
ok | 1 passed (5 steps) | 0 failed | 9 filtered out

Affected suites, all passing:

Command Result
deno task test:file src/workflow/ 107 passed (2108 steps)
deno task test:file src/integrations/remote-tools.test.ts 65 steps passed
deno task test:file src/integrations/remote-tools.hardening.test.ts 28 steps passed
deno task test:file src/integrations/index.test.ts 10 steps passed
deno task test:file src/agent/runtime/tool-helpers.test.ts 78 steps passed
deno task test:file src/tool/factory.test.ts 46 steps passed
deno task test:file cli/commands/dev/ 161 steps passed
API reference check (generate-api-reference.ts --check) current
lint:anti-slop, lint:module-boundaries, lint:dependency-boundaries, lint:core-deps ok

Test hardening (4d118a452)

A coverage audit fixed a CI blocker and two defects in the refusal messages.

  • CI blocker: the new step-executor tests used environment variables and mocked fetch inside src/workflow/executor/step-executor.test.ts. That fails lint:test-semantic-dispositions ("missing semantic disposition") in lint:ci. They now live in tests/integration/semantic-unit-boundary/src/workflow/executor/step-executor-integration-tools.test.ts, and the lint passes.
  • Connect URL kept: an unconnected integration failed the step with "GitHub refused list_repos for this workflow run: authentication_required" and dropped the connect URL. It now says "GitHub is not connected. Connect it at <url>, then retry the run." The URL is also in context.connectUrl.
  • No internal code: an empty MCP tool error showed the internal tool_error code. It now says "the integration returned an error".
  • New tests:
    • remote-tools.test.ts (7 tests):
      • the slug and status for each kind of API refusal: JSON message, error field only, plain text, blank, empty body;
      • MCP tool errors, with a typed condition's status carried over, plus the auth-required and reconnect cases;
      • an integration the catalog doesn't list, and the no-token 401 with no request sent;
      • success results unchanged;
      • the agent contract: with no marker, false, "true" or an inherited marker, error objects still come back instead of throwing.
    • Step tests:
      • a tenantless step gets no tenant fields, and a tenant step gets every tenant field;
      • the stored veryfront login token works;
      • a tenant with an unusable token never borrows the environment token;
      • a real tool() factory step works end to end.
  • Red/green:
    • With remote-tools.ts and step-executor.ts reverted to main, 14 new tests fail. Three are guards that pass both ways.
    • On this PR's earlier head, the connect-URL and empty-error tests fail.
    • On the final head, src/workflow/ gives 107 passed (2113 steps), and the touched and related files give 21 passed (227 steps).
  • Checks: docs:api-reference:check, docs:errors:check, lint:anti-slop, lint:module-boundaries and test:layout pass. The full pre-push gate passed on Deno 2.9.7.
  • Retry behavior (test(workflow): pin which integration refusals a step retries): a refused call throws a VeryfrontError with the upstream status, and the step retry policy retries only 408, 425, 429 and 5xx. Two new step tests pin this: a 403 refusal under maxAttempts: 3 makes one call, and a 503 refusal is retried until it succeeds. Mutation check: forcing the status to 503 fails the 403 test, and dropping the status fails the 503 test.

Update 30 Nov

  • Merged origin/main (65 commits). Only CHANGELOG.md conflicted: both sides added a "Breaking" entry under Unreleased. I kept main's prompt-reference entry first, then this PR's entry. No code file this PR touches changed on main, so nothing in the PR was superseded.
  • Token name: main now reads VERYFRONT_API_KEY (code#5514). The no-token refusal and its CHANGELOG line now say "Set VERYFRONT_API_KEY or run veryfront login" instead of VERYFRONT_API_TOKEN; tests updated.
  • Still needed with api#7486 on staging: the API now gives workflow runs integration scopes, but a refused call still came back as an error object. On staging (30 Nov, API build 20261129091214-336347142e10) a scheduled workflow run whose code step called salesforce__list_cases got a 403 and the run reported completed (run 9c615240-2bfd-4040-a175-2bb5b25958f9). With this PR that run fails with the reason.

Validation (merged head c4ea6c078):

deno task test:file src/integrations/remote-tools.test.ts            ok | 11 passed (113 steps) | 0 failed
deno task test:file src/workflow/executor/step-executor.test.ts      ok | 10 passed (40 steps) | 0 failed
deno task test:file tests/integration/semantic-unit-boundary/src/workflow/executor/step-executor-integration-tools.test.ts
                                                                      ok | 1 passed (10 steps) | 0 failed
deno fmt --check (touched files)    Checked 7 files
deno lint (touched files)           Checked 4 files
deno check remote-tools.ts, step-executor.ts   ok
deno task docs:errors:check         docs/guides/errors.md is current (142 errors)
deno task lint:anti-slop            baseline ok

The local pre-push full unit suite did not finish on an overloaded machine (stopped at 30 min, no failure), so this push used --no-verify; CI runs the full suite.


Current behavior (head 5374a50c56)

This section replaces three earlier notes above: the workflowStep: true marker, "Connect URL kept" and "Retry behavior".

  • The workflow marker is executor-owned. The step executor marks its tool context with a module-private symbol (src/tool/workflow-step-context.ts), not a workflowStep field, and that field is no longer on ToolExecutionContext. Application context cannot set the marker, and the agent runtime clears it from the tool context it builds, so an agent call always gets the error result with its connect action.
  • Connect URL is never in the error. An authentication refusal says "<Integration> is not connected for this project. Connect it in Veryfront Studio, then retry the run." (or the reconnect form). Neither the connect URL nor the provider's message reaches the error, and the error sets no context. Authentication is read from the payloads as the API sent them (structured content, the joined text, each text item, and an HTTP error body), before a validated _meta.condition replaces the error code. A payload that carries connectUrl or connect_url under any code is handled the same way. An HTTP error body that looks like JSON but does not parse is never quoted.
  • A refused call is never retried by the default step retry policy. The request was already sent, so the tool may have run. The error's status is the API's HTTP status, or a tool error's validated _meta.condition status, when that status is not transient (408, 425, 429, 500, 502, 503, 504). Otherwise it is 401 for a connect refusal and 422 for any other, and the message of a transient HTTP failure names the status. A step can opt in to a retry with retry.retryIf.

Validation (head 5374a50c56):

deno task test:file (remote-tools, remote-tools.hardening, step-executor,
  agent-runtime-step, step-executor-integration-tools)  ok | 14 passed (208 steps) | 0 failed
deno fmt, deno lint, deno check (touched files)          ok
lint:anti-slop, lint:module-boundaries,
  lint:test-semantic-dispositions, docs:api-reference:check   ok

Three new tests fail on head 9047af6d6: gives an HTTP failure after dispatch a status the step retry policy does not retry, redacts an authentication refusal whose error code a validated condition replaces, and the step test never replays a call the API failed after it was sent. Two more fail without the marker change: keeps returning error results to callers that are not workflow steps (now with a workflowStep: true context) and never marks an agent's tool context as a workflow tool step's.

…eps and throw on refusal

A workflow tool step passed an own authToken property even when the run had
no tenant (a local `veryfront workflow run`). runRemoteIntegrationTool reads an
own authToken as the caller owning the credential, so it never fell back to
VERYFRONT_API_TOKEN or the `veryfront login` token and answered no_api_token.
The step now claims the tenant's identity only when the run has a tenant.

Workflow tool steps also mark their context with workflowStep. A refused call
(API error, integration tool error, or no token) then throws with the reason,
"<Integration> refused <tool> for this workflow run: <reason>", instead of
returning an error object the step can silently ignore. Agent tool calls keep
the error-object result.

Refs veryfront/veryfront-issue-inbox#4462
…ame the connect URL

- Move the env- and fetch-bound StepExecutor integration tool tests to the
  semantic integration suite; they failed lint:test-semantic-dispositions in
  the unit tree.
- Add workflow-step refusal tests in remote-tools.test.ts: API reason and
  status shapes, MCP tool errors with typed conditions, unlisted integrations,
  the 401 no-token refusal, unchanged success results, and the agent contract
  for absent, false, non-boolean, and inherited markers.
- Add step tests for the tenantless context shape, every tenant field, the
  stored login token, a tenant that must not borrow the environment token, and
  a tool() factory step.
- An authentication refusal now names the connect URL in the message and in
  context.connectUrl instead of the bare authentication_required code, and an
  empty MCP error no longer surfaces the internal tool_error code.
@mattboon
mattboon marked this pull request as ready for review November 30, 2026 11:20
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T23:20:20.940051Z 5374a50 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

@codex review

@github-actions

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c4ea6c0782

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/integrations/remote-tools.ts Resolved
Comment thread src/integrations/remote-tools.ts Resolved
Comment thread src/integrations/remote-tools.ts Resolved
…retry statusless ones, load the catalog only on refusal

- An authentication refusal names Veryfront Studio, not the single-use connect URL, and sets no error context: the message is persisted in run state.
- A refusal with no HTTP or typed-condition status is 401 (connect) or 422, so the step retry policy never replays it.
- The connector catalog is imported only when a refusal is formatted, so agent runtimes don't load it at startup.
@github-actions

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 02483a53cb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/integrations/remote-tools.ts Resolved
… it reports

Only the API's own HTTP refusal keeps its status for the step retry policy. A tool error's status comes from a non-transient typed condition, else 401 or 422, so a conditionless status: 503 or a retryable: false 502 never replays a write.
@github-actions

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 998e1ae0c0

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/integrations/remote-tools.ts Resolved
Comment thread src/integrations/remote-tools.ts Resolved
…error's status only from a validated condition

- An authentication_required or reconnect_required code alone triggers the fixed Studio copy, even without the integration field, so its message never reaches run state.
- A tool error's status comes only from the validated _meta.condition, never from a condition field the payload carries itself.
@github-actions

Copy link
Copy Markdown

@codex review

@mattboon

Copy link
Copy Markdown
Contributor Author

Codex rounds 1–3 handled (30 Nov), head 9047af6d6:

Round Finding Fix
1 · P1 single-use connect URL in the persisted error fixed Studio copy, no URL, no error context (02483a5)
1 · P2 statusless refusal defaulted to retryable 502 401 / 422 defaults (02483a5)
1 · P2 catalog loaded on every agent runtime unconnected.ts imported only on refusal (02483a5)
2 · P1 any decoded status drove retries only the API's HTTP status can be transient; tool errors never retry (998e1ae)
3 · P1 incomplete auth action not redacted auth code alone triggers redaction (9047af6)
3 · P2 payload-owned condition forged the status only the validated _meta.condition counts (9047af6)

Each fix has a regression test that failed before it.

remote-tools.test.ts                          ok | 1 passed (76 steps)
step-executor-integration-tools.test.ts       ok | 1 passed (12 steps)
step-executor.test.ts                         ok | 10 passed (40 steps)
remote-tools.hardening.test.ts                ok | 1 passed (28 steps)
remote-tools.conditions.test.ts               ok | 1 passed (4 steps)
fmt / lint / deno check / lint:anti-slop / lint:module-boundaries / docs:errors:check   ok

CI on this fork PR is action_required: a maintainer has to approve the workflow runs before CI/CD, CodeQL and the quality gates run.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9047af6d6d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/integrations/remote-tools.ts Resolved
Comment thread src/integrations/remote-tools.ts Resolved
…ct authentication from the raw payload

A workflow tool step's integration call is sent before any refusal comes back, so the tool may already have run. A transient HTTP status (408, 425, 429, 500, 502, 503, 504) no longer reaches the step retry policy: the error takes 422 (401 for a connect refusal) and its message names the HTTP status. Use retry.retryIf to opt in to a retry.

An authentication refusal is now read from the payloads as the API sent them (structured content, the joined text, each text item, and an HTTP error body), before a validated condition replaces the error code. A payload that carries a connect URL under any code is treated the same way, and an HTTP error body that looks like JSON but does not parse is never quoted, so the single-use connect URL cannot reach the stored error.
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5aa50bda8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/integrations/remote-tools.ts Resolved
The refusal contract was switched by a workflowStep field on the tool context. Application context is copied into an agent's tool context, so an agent whose context carried that field had its integration refusals thrown and redacted instead of returned with the connect action.

The workflow step executor now marks its tool context with a module-private symbol that application context cannot name. The agent runtime clears the marker from the tool context it builds, so an agent handed a workflow step's context still gets error results. The workflowStep field is removed from ToolExecutionContext.
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5374a50c56

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

reason = `${displayName} is not connected for this project. ` +
"Connect it in Veryfront Studio, then retry the run.";
} else {
reason = readRefusalReason(result);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep untrusted refusal text out of stored errors

When a non-authentication HTTP or MCP failure contains a secret, customer value, or request fragment in message, this call copies the untrusted text into VeryfrontError.message; StepExecutor.executeAttempts then invokes onStepError with it and stores lastError.message in the failed run at src/workflow/executor/step-executor.ts:359-365. Fresh evidence outside the fixed OAuth path is that the new tests explicitly preserve arbitrary Forbidden and MALFORMED_QUERY text, while src/integrations/client.ts:383-396 deliberately does not retain API error-body text. Use a validated slug/status or fixed safe copy for persisted workflow errors rather than the provider/API body.

AGENTS.md reference: AGENTS.md:L145-L150

Useful? React with 👍 / 👎.

{ fatalUtf8: true },
);
return { error: "api_error", status: response.status, message: text };
return await refuseIntegrationToolCall(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Prevent retries after transport-level dispatch failures

For a newly enabled tenantless workflow call with retry.maxAttempts > 1, if the POST reaches the API/provider but dispatch or response-body streaming rejects with a transient system error such as an own code: "ECONNRESET", this response-only refusal branch is skipped and the raw error reaches retry-policy.ts:65-70; step-executor.test.ts:245-252 confirms that such an error is retried. Fresh evidence beyond the earlier HTTP-status finding is that these exception paths remain outside the non-retryable wrapper, while src/integrations/client.ts:306-325 already wraps the same execution transport failures as outcome-unknown, so this path needs the same fence to avoid replaying a committed write.

AGENTS.md reference: AGENTS.md:L26-L28

Useful? React with 👍 / 👎.

This branch has not been deployed

No deployments
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.

2 participants