Skip to content

fix(files): let Mothership tool runs write workspace files - #9685

Merged
waleedlatif1 merged 3 commits into
stagingfrom
fix/file-tools-tool-execution-delegation
Nov 4, 2026
Merged

waleedlatif1 merged 3 commits into
stagingfrom
fix/file-tools-tool-execution-delegation

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Nov 4, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Every File tool run from a Mothership chat returned 403. executeToolForCaller hands the chat's delegated principal (audience sim:tool-execution) to in-process tools unchanged, and workspace-file use cases admit only sim:workspace-files. executeFileTool now rebinds a delegated caller with rebindWorkspaceFileDelegatedPrincipal, the same helper function-execute and payload materialization use. Subject, workspace, expiry ceiling and resource scope are kept, and the file use cases still check the subject's current role. A delegation for another workspace is left unchanged so they refuse it with their normal 403. File tools are the only consumer of callerPrincipal, and its TSDoc now says consumers must rebind.
  • image_generate outside a workflow run stored every image twice. The chat-path fallback returned only a URL, so FileToolProcessor downloaded and re-uploaded it under a second key. imageUrl/content and image then pointed at different objects, and only image was content-sniffed. storeGeneratedImage now sniffs once with resolveStoredFileMetadata before storing and returns the stored file as imageFile on both paths. The processor keeps it as is, so there is one object, one sniff, and consistent output fields.
  • Storage stays inside the image operation rather than moving to storeInternalToolFileResult. That keeps storage failures inside its fal "completed but delivery failed" metering reconciliation.

Type of Change

  • Bug fix

Testing

  • New lib/internal/file/delegated-caller-write.integration.ts drives the real executeFileTool against Postgres with the principal tools execute mints:
    • Saving a chat-generated image into Workspace Files: red on staging (expected 403 to be 200), green with the fix. Re-proved after the cleanup round.
    • A read-only member gets 403, and a delegation for another workspace gets 403. Both guard against the rebind widening access.
  • lib/internal/file/execute-tool.test.ts, lib/internal/image, tools/image unit tests and bun run lint pass.
  • Full bun run test, check:audits and type-check are left to CI.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

`tools execute` authorizes the chat's delegated principal for
`sim:tool-execution` and hands it to the tool layer unchanged, but every
workspace-file use case admits only `sim:workspace-files`. Every File tool
run directly from a Mothership chat therefore failed with a 403
"Delegated workspace access is no longer valid", which the agent relayed
to the user as lost workspace access. The File tool handler now rebinds a
delegated caller to the workspace-files audience (keeping subject,
workspace, expiry ceiling and resource scope), as function-execute and
payload materialization already do; the file use cases still check the
subject's current workspace role.

`image_generate` outside a workflow run returned only a URL for its
copilot-storage upload, so the file-output processor downloaded and
re-uploaded it, storing every image twice under two keys and returning
`imageUrl` and `image` that disagreed. It now returns the stored file.
@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 4, 2026 11:10pm UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge.

Summary

Lets Mothership File tools use workspace-file operations and avoids storing generated images twice.

  • Mothership chat File writes reach Workspace Files.
  • Generated images return one stored file on both paths.

Reviews (3) · Last reviewed commit: "chore(files): import the principal facto..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 3 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

…legations with 403

Generated images are now content-sniffed before they are stored, so every
output field references the same verified object on both the workflow and
chat paths; skipping the re-upload had otherwise skipped the sniff it did.
A delegation minted for another workspace is no longer rebound (which
threw and surfaced a 500); the workspace-file use cases refuse it with
their ordinary 403. The regression test now uses the shared principal
factory and uploads mock.
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit c4ccdde into staging Nov 4, 2026
80 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/file-tools-tool-execution-delegation branch November 4, 2026 23:38

This branch was previously deployed

1 inactive deployment
Preview — aa7c133e Deployed Nov 4, 2026 by vercel[bot]
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