# Continuity ledger (per-branch)

## Human intent (must not be overwritten)

- Reuse the same `GiselleClientProvider` wiring (server actions mapped to `GiselleClient`) across Studio pages like playground/tasks, without copy-pasting a huge mapping object.

## Goal (incl. success criteria)

- `useGiselle()` works in `(main)` routes (e.g. stage input file uploads) by having a single `GiselleClientProvider` mounted in the authenticated app shell.
- Workspace editor page (`app/workspaces/[workspaceId]`) continues to work, but reuses the shared client mapping.
- No duplicated “mappedClient” object across pages.

## Constraints/Assumptions

- Assume login-only; mount provider only under `app/(main)/layout.tsx` (do not touch root `app/layout.tsx`).
- Keep the change minimal and consistent with existing `@/lib/internal-api` server action exports.

## Key decisions

- Extract the mapping into `createInternalGiselleClient()` so both `(main)` layout and the workspace editor page share a single definition.

## State

- `useStageInput()` already calls `useGiselle()` and needs a `GiselleClientProvider` in-tree.

## Done

- Added `createInternalGiselleClient()` factory.
- Added `(main)`-scoped provider wrapper and mounted it in `app/(main)/layout.tsx`.
- Refactored workspace editor page to use the shared factory.
- Fixed a Studio playground attachment regression: corrected `apps/studio.giselles.ai/app/basePath.ts` to export `/api/giselle` (was `/api/giselles`), matching `app/giselle.ts` and preventing 404s for uploaded image previews.
- Restored “oversize upload” UX after switching uploads to Server Actions by adding a 4.5MB client-side precheck (file-panel style) + unified error message, and a defense-in-depth server-side guard.
- Fixed a cancellation race in `ImageGenerationRunner`: once stop is requested, we avoid overwriting the local `cancelled` status with `failed`/`completed`.
- Added an inline comment explaining the intentional early `return` in the cancellation path (to prevent regressions).
- Added a TODO comment noting that user cancellation should ideally not surface as an error (reduce log/telemetry noise).

## Now

- Tooling note: this environment required `mise` shims to run `pnpm` commands.
- Ran `pnpm tidy` (Knip) and fixed all reported issues until it ran cleanly.
- Ran Biome formatting on modified files (note: paths with `(main)` need quoting under zsh).

## Next

- Run `pnpm biome check --write` on the touched files and a quick typecheck locally.
- Decide/confirm the actual Server Actions body size limit for Studio and align the single source of truth (possibly via `experimental.serverActions.bodySizeLimit`).

## Open questions (UNCONFIRMED if needed)

- Should we also mount `GiselleClientProvider` for non-`(main)` authenticated routes beyond the workspace editor page, or keep wrapping them case-by-case?

## Working set (files/ids/commands)

- `apps/studio.giselles.ai/lib/internal-api/create-giselle-client.ts`
- `apps/studio.giselles.ai/app/(main)/internal-giselle-client-provider.tsx`
- `apps/studio.giselles.ai/app/(main)/layout.tsx`
- `apps/studio.giselles.ai/app/workspaces/[workspaceId]/page.client.tsx`
- `apps/studio.giselles.ai/app/basePath.ts`
- `apps/studio.giselles.ai/app/(main)/playground/file-attachments.tsx`
- `apps/studio.giselles.ai/lib/internal-api/tasks.ts` (removed unused export)
- `apps/studio.giselles.ai/app/(main)/components/stage-input/use-stage-input.ts` (4.5MB precheck + unified message)
- `internal-packages/workflow-designer-ui/src/app-designer/store/usecases/use-upload-file.ts` (4.5MB precheck + unified message)
- `apps/studio.giselles.ai/lib/internal-api/files.ts` (server-side size guard)
- `packages/react/package.json` (removed unused dependency)
- `packages/react/src/generations/generation-runner.tsx` (guard stop→cancelled from being overwritten)
- Command: `pnpm tidy`
- Command: `pnpm biome check --write "<paths...>"`

