Skip to content

refactor: enforce Copilot table application boundary - #6453

Draft
TheodoreSpeaks wants to merge 7 commits into
improvement/v2-endpointsfrom
improvement/v2-copilot-table-boundary
Draft

refactor: enforce Copilot table application boundary#6453
TheodoreSpeaks wants to merge 7 commits into
improvement/v2-endpointsfrom
improvement/v2-copilot-table-boundary

Conversation

@TheodoreSpeaks

@TheodoreSpeaks TheodoreSpeaks commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Replace the Table Copilot admission-only compatibility paths with fixed application commands that own canonical loading, asserted-workspace checks, authorization, mutation, audit, and shared effects.
  • Keep the shared in-process Copilot identity (serviceId: copilot) from the merged foundation. Fixed adapters construct that Principal, map boundary input, call exactly one code-defined application command/query, and present the result; there is no generic Table multi-operation executor.
  • Replace automatic tool-output persistence with one schema-locked Table command. It validates projected wire rows against the fresh authoritative schema and replaces rows in the same lock/transaction, removing the former read-then-write race.
  • Add named Table commands for workflow-group create/update/add-output and enrichment creation. They resolve canonical workflow metadata only after Table authorization, conceal cross-workspace workflow IDs, validate requested coordinates/mappings, construct groups and columns, mutate, audit, and emit shared effects. No authorized use case is nested inside another.
  • Make create-from-file, import-file, ordinary workspace-file-backed import creation, and best-effort multi-table deletion top-level application commands. They own their complete compound semantics rather than composing authorized lower-level use cases in the Copilot adapter.
  • Return domain import/export records from application code and present unchanged v2 DTOs only at route presenters. Preserve v1 behavior and schemas. No database migration or dependency change is included.

Application operation manifest

Migrated

Table Copilot operations

  • Table lifecycle: create, get, get schema, rename, and ordered best-effort multi-table delete. The delete command canonically resolves every requested table in the trusted workspace and records each completed archive even if a later mutation fails.
  • Rows: insert, batch insert, get, query, update, delete, filter update/delete, batch update/delete, and automatic tool-output replacement. Each calls a fixed Table use case; projected output replacement validates and writes under one authoritative schema lock.
  • Columns: add, rename, single/multi-delete, and constraint/type/options update through fixed Table application use cases.
  • Workflow groups: create, update, delete, add output, and delete output. Named create/update/add-output commands own workflow resolution, validation, group/column construction, mutation, audit, schema effects, and auto-run dispatch.
  • Enrichment: creation owns enrichment lookup, input/output mapping validation, group/column construction, mutation, audit, and effects.
  • Runs: start and cancel enter fixed Table application use cases.
  • Workspace files: create table from file and import file into table are top-level cross-resource Table commands. They own canonical file/table resolution and authorization, exact provenance binding, bounded inline parsing, large-file background admission, job claims, abort checks, partial append behavior, and create rollback.

Workflow operation

  • list_workflow_outputs calls one exact authorized Workflow resolver using the shared Copilot Principal. Workflow-output resolution used by group mutations is owned inside the top-level authorized Table command and is not a nested Workflow use case.

HTTP Table transfer/group operations

  • Internal and v2 import create/read/cancel, multipart part signing, and completion call fixed Table import use cases.
  • Internal and v2 export create/read/cancel and download authorization/signing call fixed Table export use cases.
  • Ordinary internal workflow-group create/update/delete routes call fixed Table application use cases.
  • Import/export application code returns domain records; internal/v2 presenters perform wire DTO conversion.

Deferred

  • None. No authorize-only Table shim, compatibility allowlist, generic Table executor, adapter-to-manager mutation, or adapter-composed authorized command remains in the declared PR scope.

Non-goals

  • Knowledge operations: this Table domain PR changes no Knowledge route or Copilot operation. The merged shared Knowledge/application adapter foundation is consumed as-is and is not duplicated here.
  • Multipart protocol mechanics, signed-part transport, binary download responses, and streaming/large-body transport remain specialized. Their durable resources, authorization, immutable upload binding, and signing decisions are application-owned.
  • list_enrichments is a pure code-defined catalog presentation with no durable resource load or mutation; it is intentionally not forced through the Table operation registry.
  • Tool argument parsing, response/error presentation, abort polling, and trusted model-response secret-provenance propagation remain surface concerns. They do not authorize or mutate Table resources.
  • v1 and unrelated legacy Table routes are unchanged.

Import and internal-auth policy

Durable import resources are workspace-owned: reading an import requires workspace read access, and cancelling an import requires workspace write access. This intentionally allows a currently authorized workspace member or workspace API key to control the durable job independent of the original uploader.

Upload control remains credential-bound. Upload parts, completion, and upload cancellation require the exact creating principal/API-key credential plus the upload token; finalization reasserts that binding. Delegated principals remain rejected from HTTP upload creation, parts, and completion. Copilot workspace-file imports enter delegated-only Table application commands instead of entering or bypassing the HTTP upload lifecycle.

The ordinary first-party transfer and workflow-group routes are session-only. A caller audit found only browser React Query callers and no workflow executor or trusted server caller sending Bearer auth to these contracts. Executor Bearer support is therefore not applicable here: this PR adds neither createInternalSessionOrExecutorAuth nor a dead delegation-token abstraction, and it never derives executor authority from a route workspace, uploader, owner, or billing actor. Any future executor caller must use scoped headers generated from canonical workflow execution context.

Foundation

This branch is rebased on d69224595c and consumes the merged delegated identity, consolidated Copilot adapter, and route-boundary foundations from #6462, #6450, and #6451. No duplicate fallback Principal or workspace executor is included.

Validation

  • Focused Vitest: 24 files, 167 tests passed
  • Sim and @sim/auth type-check passed
  • Biome passed on all 59 PR-changed files
  • bun run check:api-validation:strict passed
  • git diff --check passed

bun.lock contains unrelated local tool-version drift and is intentionally excluded.

@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Aug 9, 2026 5:54pm

Request Review

@TheodoreSpeaks
TheodoreSpeaks force-pushed the improvement/v2-copilot-table-boundary branch from 81faf24 to d0493ad Compare August 9, 2026 00:45
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor

cursor Bot commented Aug 9, 2026

Copy link
Copy Markdown

PR Summary

High Risk
Large refactor across Copilot table persistence, authorization, workflow-group validation, and import/export HTTP paths; behavior regressions could affect data writes, cross-workspace workflow binding, and API response shapes despite preserved contracts.

Overview
This PR removes the generic Table Copilot executor (executeCopilotTableUseCase / admitCopilotTableOperation) and routes Copilot through fixed table-commands adapters that each call one authorized application command with a delegated Copilot principal.

Automatic tool-output and CSV/JSON table persistence no longer read the table in the adapter and replace rows separately; they call replaceProjectedWireRows, which validates projected wire rows against the schema under the table lock before replacing rows in one transaction.

Internal first-party table routes for workflow groups, imports, and exports are rewritten from hand-rolled withRouteHandler auth/access/orchestration to defineInternalJsonRoute wired to the same application use cases as v2. Group routes keep TableLockedError mapping via an extended error policy. Import/export create contracts now declare 201 responses.

v2 import/export presenters are centralized in presentV2TableImport / presentV2TableExport so routes map domain records to wire DTOs at the boundary. Workflow output listing for Copilot moves to executeCopilotResolveWorkflowOutputs calling the fixed resolveWorkflowOutputs command.

Table delegation rejects empty table IDs in resolveCopilotTablePrincipal. Tests shift from integration-style HTTP mocks to route-definition wiring tests and updated Copilot tool tests aligned with the new command surface.

Reviewed by Cursor Bugbot for commit d7df662. Bugbot is set up for automated code reviews on this repo. Configure here.

@greptile-apps

greptile-apps Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR moves Copilot and HTTP Table operations behind fixed application commands that own canonical loading, authorization, mutation, audit, and shared effects.

  • Replaces the generic Copilot Table executor and compatibility admission paths with operation-specific adapters and use cases.
  • Binds single-table Copilot principals to the requested table while keeping creation and multi-table deletion workspace-scoped.
  • Moves import, export, workflow-group, enrichment, row, column, lifecycle, and workspace-file operations into the Table application boundary.
  • Keeps route handlers focused on authentication, input mapping, error policy, and DTO presentation.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/lib/copilot/application/table-commands.ts Introduces fixed Copilot adapters that dispatch each operation to one application command and bind single-table principals to the target table.
apps/sim/lib/copilot/auth/table-delegation.ts Rejects blank table scopes and constructs delegated Table principals with the requested resource scope.
apps/sim/lib/table/application/authorization.ts Enforces exact delegated table-scope matching whenever the canonical authorization context contains a table ID.
apps/sim/lib/table/application/copilot-table-lifecycle.ts Implements workspace-scoped lifecycle commands, including per-table canonical workspace checks for best-effort deletion.
apps/sim/lib/table/application/rows.ts Moves projected-row replacement into an authorized, schema-validated, locked application command.
apps/sim/lib/table/application/imports.ts Centralizes durable import authorization and credential-bound upload control in fixed application use cases.
apps/sim/lib/table/application/exports.ts Centralizes export creation, access, cancellation, and download authorization in application use cases.
apps/sim/lib/table/application/groups.ts Moves workflow-group and enrichment mutations behind canonical Table authorization and application-owned effects.
apps/sim/lib/copilot/tools/server/table/user-table.ts Routes Table tools through fixed application use cases with table-scoped principals for single-table operations.
apps/sim/app/api/table/[tableId]/groups/route.ts Reduces group routes to session-authenticated boundary mapping, application dispatch, error policy, and presentation.

Sequence Diagram

sequenceDiagram
  participant Model as Copilot model
  participant Adapter as Fixed Table adapter
  participant Command as Table application command
  participant Auth as Authorization policy
  participant Store as Canonical Table storage
  Model->>Adapter: Tool call with tableId
  Adapter->>Adapter: Construct delegated principal scoped to tableId
  Adapter->>Command: Execute one code-defined command
  Command->>Store: Load canonical table and workspace
  Command->>Auth: Authorize principal against canonical context
  Auth-->>Command: Scope and permission decision
  Command->>Store: Locked mutation or query
  Command-->>Adapter: Domain result
  Adapter-->>Model: Presented tool result
Loading

Reviews (7): Last reviewed commit: "fix(tables): reject enrichment output mu..." | Re-trigger Greptile

Comment thread apps/sim/lib/copilot/application/execute-table-use-case.ts Outdated
Comment thread apps/sim/lib/table/application/workspace-file-imports.ts Outdated
Comment thread apps/sim/lib/table/application/workspace-file-imports.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 2856cd5. Configure here.

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

Comment thread apps/sim/lib/table/application/groups.ts
Comment thread apps/sim/lib/table/application/groups.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 54e16a0. Configure here.

@TheodoreSpeaks
TheodoreSpeaks force-pushed the improvement/v2-copilot-table-boundary branch from 54e16a0 to ecae9b8 Compare August 9, 2026 15:05
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

Comment thread apps/sim/lib/table/application/groups.ts
@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@cursor review

@TheodoreSpeaks

Copy link
Copy Markdown
Collaborator Author

@greptile

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d7df662. Configure here.

@TheodoreSpeaks
TheodoreSpeaks marked this pull request as ready for review August 9, 2026 18:52
@TheodoreSpeaks
TheodoreSpeaks marked this pull request as draft August 9, 2026 18:57
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