Skip to content

Give each issue its own execution workspace - #17156

Open
jjude80 wants to merge 6 commits into
paperclipai:masterfrom
jjude80:fix/per-issue-execution-workspace-isolation
Open

jjude80 wants to merge 6 commits into
paperclipai:masterfrom
jjude80:fix/per-issue-execution-workspace-isolation

Conversation

@jjude80

@jjude80 jjude80 commented Oct 22, 2026 •

Copy link
Copy Markdown

Thinking Path

  • Paperclip is the open source app people use to manage AI agents for work
  • The execution workspace decides where a run writes its files and commits
  • An isolated workspace is one issue's worktree, with one branch and one index
  • A child issue inherits the workspace row of its parent
  • When a parent issue is decomposed, every child inherits the same isolated workspace
  • The children then run in one worktree at the same time
  • This pull request gives every issue its own workspace
  • The benefit is that one run cannot delete or publish the work of another run

Linked Issues or Issue Description

What happened?

A child issue inherited the execution workspace row of its parent, not only the mode and the settings. The dispatch code reused any workspace the issue already pointed at. It did not check who owned that workspace.

When a feature was decomposed into six children, all six children carried the same executionWorkspaceId with the preference reuse_existing. Four runs were live in one worktree at the same time. The cost was measured:

  • A whole file write deleted the edits of another run.
  • git commit published every staged path in the tree, including the paths of another issue.
  • The tree did not build, for reasons that belonged to neither run.

Expected behavior

A child of a decomposed parent gets its own execution workspace. A run never joins a worktree that another issue owns.

Steps to reproduce

  1. Create a parent issue in a project whose policy is isolated_workspace with git_worktree.
  2. Give the parent an execution workspace. It is an isolated workspace.
  3. Create two child issues of that parent.
  4. Dispatch the children at the same time.
  5. Group the issues by executionWorkspaceId. Both children have the workspace of the parent.
  6. Look in the worktree of the parent. The runs of both children write in it.

Paperclip version or commit

master at 00818634.

Deployment mode

A running deployment of this server.

Installation method

Managed install store, npm source.

Agent adapter(s) involved

Not adapter-specific (core bug).

Database mode

Not adapter-specific (core bug).

Access context

Operator.

Node.js version

Node.js 24.

What Changed

The rule has two layers, because a creation-time rule alone does not cover an issue that already points at a foreign workspace.

Layer 1 — creation time (server/src/services/issues.ts, server/src/services/execution-workspace-policy.ts)

An isolated_workspace is a per-issue workspace: one git worktree, one branch, one index, cut for one issue. Binding a second issue to it does not make the tree shared in some softer sense. It puts two runs in the same working tree, where a whole-file write destroys the other run's edit, git commit publishes the other run's staged paths, and the tree does not build for reasons that belong to neither run.

A shared_workspace is a different animal. It is shared by design, it is not a per-issue branch, and inheriting it is how a child continues its parent's work in the project checkout. The rule therefore keys on the mode of the workspace being inherited, not on the relationship between the two issues.

  • resolveExecutionWorkspaceInheritanceDecision decides whether a child binds the workspace row of its parent. An explicit workspace override on the child inherits nothing.
  • buildInheritedExecutionWorkspaceSettings builds the settings a child carries. The mode always travels: a child of an isolated parent is still an isolated task, it just gets an isolated workspace of its own. A pinned exact branch does not travel, for the same reason the workspace row does not: existingBranch names one branch, and a branch is the thing two issues must not share.

Layer 2 — dispatch time (server/src/services/heartbeat/workspaces.ts, server/src/services/heartbeat/queue.ts, server/src/services/heartbeat/environment-selection.ts, server/src/services/heartbeat/workspace-preparation.ts)

  • The reuse request now carries the issue, the mode of the workspace and the issue that owns it. Reusing an isolated workspace owned by a different issue is refused, and the refusal names the holder in conflictingWorkspaceOwnerIssueId. Recovery keeps its own workspace: a run that continues work in a tree is not a second issue that joins it.
  • resolveExecutionWorkspaceStrategyConfig drops a pinned workspaceStrategy.existingBranch when the reuse was refused. Refusing the reuse is not enough on its own: a child that carries a pinned branch still realizes into the holder's checkout, because realization finds the worktree registered for that branch and reuses it. The run was refused a workspace and then given the same tree by another door. With the branch dropped, the child derives its own branch and its own worktree. The workspace preparation uses this for the effective run config, the plugin preparation and the realization.
  • The refusal is loud. The preflight posts a comment that names the holder issue, with the HTML marker workspace_conflict:<workspaceId>, so the board does not repeat it. The run learns whose tree it was about to write into, before it writes.

Comments

This branch adds no code comments. CONTRIBUTING.md says "Do not submit a PR that includes code comments", so the reasoning above lives here instead.

Tests

  • server/src/__tests__/execution-workspace-policy.test.ts — 53 cases: the inheritance decision, the inherited settings, and the strategy resolution (a pinned branch is dropped for a foreign owner, kept for the issue's own workspace, and the whole strategy is dropped when the branch was all it held).
  • server/src/__tests__/issues-service.test.ts — 32 workspace cases: a child of an isolated parent does not get the parent's row, a child of a shared parent still does, a pinned branch is stripped, an explicit override is honoured.
  • server/src/__tests__/heartbeat-workspace-session.test.ts — the dispatch path: the refusal names the holder, and a refused child does not carry a pinned branch into realization.

Verification

  • Run pnpm --filter @paperclipai/server typecheck. The result is clean.
  • Run pnpm --filter @paperclipai/server test -- src/__tests__/execution-workspace-policy.test.ts. The result is 53 cases passed.
  • Run pnpm --filter @paperclipai/server test -- src/__tests__/issues-service.test.ts. The 32 workspace cases pass.
  • Run pnpm --filter @paperclipai/server test -- src/__tests__/heartbeat-workspace-session.test.ts. The workspace session cases pass, including the new refusal cases.
  • Manual check: create a parent issue with an isolated workspace, create two children, and dispatch them. The children do not inherit the workspace row of the parent, and each child gets a workspace of its own.

Risks

The behaviour change is narrow. A shared workspace is still inherited. An issue with an explicit workspace override inherits nothing. The dispatch refusal only applies to isolated workspaces. Recovery keeps its own workspace.

The one behaviour that changes for an existing issue is a child that carries a pinned branch inherited from its parent: it no longer realizes into the parent's checkout. That is the case the review flagged, and the child gets its own worktree instead.

The risk is that a workflow which relied on a child sharing the isolated worktree of its parent now gets a separate tree. That workflow is the bug this pull request fixes.

Model Used

  • Provider: Minimax
  • Model: MiniMax M3.1 Flash (opencode provider, minimax-m3.1-flash-free)
  • Context window: 1M
  • Reasoning mode: none
  • Capabilities: tool use, code execution, shell

Checklist

  • I have included a thinking path that traces from project context to this change
  • I have specified the model used (with version and capability details)
  • I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work
  • dedup-search: I have searched GitHub for duplicate or related PRs and linked them above (fix: skip execution-workspace inheritance from a terminal parent issue #13182, fix(issues): do not inherit an execution workspace into a child bound to another repository #16911, Prepare the server UI dist before staging a git payload #17163)
  • I have either (a) linked existing issues with Fixes: # / Closes: # / Refs: # OR (b) described the issue in-PR following the relevant issue template
  • I have not referenced internal/instance-local Paperclip issues or links (only public GitHub #NNN / github.com/paperclipai/paperclip URLs)
  • My branch name describes the change (e.g. docs/..., fix/...) and contains no internal Paperclip ticket id or instance-derived details
  • I have run tests locally and they pass
  • I have added or updated tests where applicable
  • I have updated relevant documentation to reflect my changes
  • I have considered and documented any risks above
  • All Paperclip CI gates are green
  • Greptile is 5/5 with no open P2s, recommendations, or follow-ups
  • I will address all Greptile and reviewer comments before requesting merge

Related pull requests

@commitperclip

commitperclip Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

✅ All checks passing — ready for Greptile review and maintainer approval.

— commitperclip

@greptile-apps

greptile-apps Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The changes affect issue workspace creation, server dispatch, and managed Git installs.

The PR should preserve the parent's intended commit before merging, so children do not start from older files.

Findings

  1. P1 Children miss parent commits ▶
Fix with agent prompt
### Issue 1
server/src/services/execution-workspace-policy.ts:449-450
The child now inherits the parent's branch name as `baseRef`, but `resolveAuthoritativeBaseRef` prefers `origin/<branch>` whenever that remote branch exists. If the parent has local commits that it has not pushed, the child starts from the older remote commit and misses the parent's latest work. Its run may fail or redo work already completed.

Preserve the intended parent commit, for example by resolving its local branch to a commit before saving the child's settings.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

Gives isolated issues separate workspaces while preserving shared-workspace inheritance.

  • Children keep isolated settings without inheriting a parent’s worktree.
  • Dispatch refuses to reuse an isolated workspace owned by another issue.
  • Managed Git installs prepare the server UI before bundling packages.

The earlier unnumbered findings are addressed: exact branch pins are removed before preparation, added code comments are gone, and the PR description includes the required sections.

Reviews (5) · Last reviewed commit: "Merge pull request #3 from jjude80/fix/w..." · Reviewed by Greptile

@jjude80

jjude80 commented Oct 22, 2026

Copy link
Copy Markdown
Author

Both branches now carry the same head, and the head moved: 56e170fa closes the second door into the same failure that the earlier commit closed for the local realization path.

What the earlier fix did. A child that carries a pinned workspaceStrategy.existingBranch could realize into the holder's checkout, because realization finds the worktree registered for that branch and reuses it. The dispatch path now drops the pinned branch when the reuse was refused, so the child derives its own branch and its own worktree.

What was still open. The refusal decided the local realization path only. prepareHeartbeatWorkspace still passed issueRef.executionWorkspaceId to preparePluginWorkspace, which loads that row and adopts its saved provider binding. A refused child was therefore handed the holder's storage through the other door.

What 56e170fa changes. One decision now feeds both preparation paths: resolveExecutionWorkspaceReuseWorkspaceId returns the reusable workspace when the issue owns it, the requested workspace when nobody else owns it, and no workspace at all when the request was refused because another issue owns it. The plugin preparation receives that value instead of the issue's own pointer.

Two smaller things in the same commit, both raised by the review on the sibling branch: the admission notice is now emitted only for a reuse request that was actually refused, and it states the observed result instead of promising a replacement; and the duplicate-notice check is a bounded query in the database instead of a scan of every comment body of the issue.

Tests. execution-workspace-policy covers the three cases of the workspace id decision and the notice rule. heartbeat-workspace-session covers the id the plugin preparation receives for a refused child and for an issue that owns its workspace.

An isolated execution workspace is one issue's worktree: one directory, one
branch, one index. A child of a decomposed parent inherited the parent's
workspace row, so six children of one decomposed parent were dispatched into the parent's
worktree and four runs were live in it at once. The cost was measured: a
whole-file write deleted another run's edits, git commit published every
staged path in the tree including another issue's, and the tree did not
build for reasons that belonged to neither run.

Two layers, because a creation-time rule alone does not cover an issue that
already points at somebody else's workspace.

1. Creation time (issues.ts). A child inherits the parent's mode and
   settings, but not the parent's workspace row when that row is an isolated
   workspace. A shared workspace is still inherited: sharing it is the point
   of it. A pinned existingBranch is stripped from inherited settings when
   the workspace is not bound, because a branch is the thing two issues
   must not share.

2. Dispatch time (heartbeat/workspaces.ts). The reuse request now carries
   the issue, the workspace mode and the workspace owner. Reusing an
   isolated workspace owned by a different issue is refused, and the refusal
   names the holder through conflictingWorkspaceOwnerIssueId. Recovery keeps
   its own workspace: a run that continues work already done in a tree is
   not a second issue joining it.

The refusal is loud. The queue preflight posts an issue comment naming the
holder issue, deduplicated by an HTML marker, so the run learns whose tree
it was about to write into instead of discovering it in a merge conflict.

Tests: execution-workspace-policy (50 cases), issues-service (32 workspace
cases), heartbeat-workspace-session (182 cases, including the new
conflict cases). Typecheck clean.
`paperclipai install --repo <owner/name> --ref <branch>` could not build a
payload at all: the server package ships the built UI inside it, and
prepare-bundled-package.mjs copies server/ui-dist into the staged package.
A fresh git checkout has no server/ui-dist -- it is produced by
scripts/prepare-server-ui-dist.sh, which the server package's own prepack
hook runs, and prepack only runs on `pnpm pack`. This flow stages the server
package directly, so the hook never fires and the packaging step died with

    Error: ENOENT: no such file or directory, lstat '.../source/server/ui-dist'

after the whole build had already run (~20 minutes).

Build the UI before the workspace packages are staged, the same way
scripts/release.sh does it before it packs. Without this, a fork branch
cannot be installed on an instance at all, which is the only supported way
to ship a fork build, and the managed install store's git source cannot be
used.

Test: cli/src/__tests__/install-command.test.ts now asserts the UI
preparation runs, and that it runs before prepare-bundled-package.mjs
stages the bundled package.
A review found a hole in the refusal: refusing the reuse of another issue's
isolated workspace is not enough on its own. A child that carries a pinned
workspaceStrategy.existingBranch still realizes into the holder's checkout,
because realization finds the worktree registered for that branch and reuses
it. The run was refused a workspace and then given the same tree by another
door.

The dispatch path now drops the pinned branch when the reuse was refused
because the workspace belongs to another issue, so the child derives its own
branch and its own worktree. The strategy config is resolved through
resolveExecutionWorkspaceStrategyConfig, which the workspace preparation uses
for the effective run config, the plugin preparation and the realization.

Tests: execution-workspace-policy covers the strategy resolution (a pinned
branch is dropped for a foreign owner, kept for the issue's own workspace, and
the whole strategy is dropped when the branch was all it held);
heartbeat-workspace-session covers the dispatch path, from the refusal through
the effective strategy the run realizes with.
…pace

The dispatch-time refusal stopped the local realization path from restoring
another issue's isolated workspace, and the pinned branch is dropped so the
child cannot find the holder's registered worktree by name.

The plugin preparation path still adopted the holder's workspace row.
prepareHeartbeatWorkspace passed issueRef.executionWorkspaceId to
preparePluginWorkspace, which restores that row and its saved provider
binding, so a refused child was handed the holder's storage through the
other door. The refusal now decides the workspace id that both preparation
paths use: a refused child gets no existing workspace id, and an issue that
owns its workspace keeps it.

The admission notice is emitted only for a refused reuse request, and it
states what was observed instead of promising a replacement. The duplicate
check asks the database for a bounded match instead of loading every
comment body of the issue into the process.

Tests: the policy suite covers the workspace id decision and the notice
rule, and the workspace session suite covers the id the plugin preparation
receives for a refused child and for an issue that owns its workspace.
@jjude80
jjude80 force-pushed the fix/per-issue-execution-workspace-isolation branch from 56e170f to 774f7ae Compare October 22, 2026 22:35
@jjude80

jjude80 commented Oct 22, 2026

Copy link
Copy Markdown
Author

Note for reviewers: the branch history was rewritten to reword the commit subjects, and the head is now 774f7aed. Both pull requests point at that head.

The trees are unchanged apart from removed code comments, so the review findings discussed above still apply to the new head. CI is re-running on it.

@jjude80

jjude80 commented Oct 22, 2026

Copy link
Copy Markdown
Author

CI status on 774f7aed: 97 checks pass. One fails — ci / e2e shard (5/8) — on tests/e2e/cases-read-only.spec.ts, at the assertion that the case-list filter button shows the selected option:

Error: expect(locator).toHaveText(expected) failed
Timeout: 5000ms
> 92 | await expect(page.getByRole("button", { name: `Filter by ${filter}`, exact: true })).toHaveText(option);

The tree is identical to 56e170fa apart from removed code comments, so there is no logic difference between the head that passed this shard and the head that failed it. The e2e config sets retries: 0, so one timing failure reds the shard. The job cannot be re-run from a fork, so this needs a maintainer re-run rather than a code change here.

jjude80 and others added 2 commits October 23, 2026 02:10
A child task inherits its parent's workspace settings but gets its own
worktree. The inherited strategy had no base ref, so the new worktree was
cut from the project default (origin/main). When the parent's work lives on
an integration branch, the child's tree cannot contain the files the task
is about, and the child waits on a baseline that can never go red.

Carry the parent workspace's branch to the child as workspaceStrategy.baseRef,
and keep a pinned existingBranch as the base ref when the pin has to be
dropped because the workspace belongs to another issue.
NEXA-482: base a child task on its parent integration branch
Comment on lines +449 to +450
if (parentIntegrationBranch) {
nextStrategy.baseRef = parentIntegrationBranch;

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.

P1 Children miss parent commits

The child now inherits the parent's branch name as baseRef, but resolveAuthoritativeBaseRef prefers origin/<branch> whenever that remote branch exists. If the parent has local commits that it has not pushed, the child starts from the older remote commit and misses the parent's latest work. Its run may fail or redo work already completed.

Preserve the intended parent commit, for example by resolving its local branch to a commit before saving the child's settings.

Prompt To Fix With AI
This is a comment left during a code review.
Path: server/src/services/execution-workspace-policy.ts
Line: 449-450

Comment:
**Children miss parent commits**

The child now inherits the parent's branch name as `baseRef`, but `resolveAuthoritativeBaseRef` prefers `origin/<branch>` whenever that remote branch exists. If the parent has local commits that it has not pushed, the child starts from the older remote commit and misses the parent's latest work. Its run may fail or redo work already completed.

Preserve the intended parent commit, for example by resolving its local branch to a commit before saving the child's settings.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

@greptile-apps

greptile-apps Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

Want your agent to iterate on Greptile's feedback? Try greploops.

cryppadotta added a commit that referenced this pull request Nov 2, 2026
## Thinking Path

> - Paperclip manages AI agents and their work.
> - Task creation can bind a child to its parent's execution workspace.
> - Native sandbox runs reserve that workspace before the provider
starts.
> - Remote reservation rejected inherited isolated workspaces and
operator branches because the original source task differed.
> - This check stopped valid child tasks before their existing access
and writer checks could run.
> - This pull request uses the persisted binding and existing
source-access checks to admit that continuation.
> - The benefit is that authorized child tasks can continue saved work
while the single-writer lock stays effective.

## Linked Issues or Issue Description

**What happened?**

A child inherited an active isolated remote workspace through normal
task creation. Its next run failed during setup with `Workspace
ownership changed.` No provider work started. The reservation guard
treated the original `sourceIssueId` as exclusive ownership, although
task creation had persisted a valid child binding.

**Expected behavior**

A bound child or follow-up can reserve the workspace after the prior
writer saves. Current task/run access, source visibility, trust, company
scope, closed-workspace state, and writer checks must still apply. The
original source task remains provenance.

**Steps to reproduce**

1. Create a task with an active saved remote isolated workspace or
operator branch.
2. Create a child without an explicit workspace override.
3. Confirm that the child inherited the execution workspace ID.
4. Start its native sandbox run. The old reservation guard rejects it
before provider execution.

**Paperclip version or commit**

Reproduced on source based on
`06bc8db75c71142ed108e0f331394c5187015d6a`. The same guard is present at
`1a6017d6460267ad89d7e1784e2b521c28d8e9ac`.

Related: #17156 proposes separate workspaces for child tasks. This
repair preserves the current inheritance contract and enforces the
remote writer lock. #16911 addresses child bindings across repositories.

## What Changed

- Remove the original-task equality restriction for active remote
workspaces. Keep the existing persisted-binding and retained-source
authorization path. Explicit task-root selection follows the existing V1
filesystem contract; task-assignment grants do not define filesystem
permissions.
- Keep closed workspace rejection and unfinished-writer checks.
- Add database-backed regressions for inheritance, replay, competing
children, an unbound task, private source data, company isolation, and
closed records.
- Extend real save/restore tests for inherited isolated workspaces and
operator branches. Keep shared-workspace discovery coverage.
- Update the development guide and workspace maps.

## Verification

- Red: before the repair, the inherited isolated/operator cases fail
with `Workspace ownership changed.` The shared case passes. The unfixed
suite has five failures and four passes.
- Green: 11 reservation cases pass with real PostgreSQL 18 in an
isolated Docker container.
- An earlier run of the four affected workspace/preparation/trust suites
passed 191 tests. The review follow-up passes all 15 selected
reservation/save/restore cases. Inherited cases remove the original
files, use a distinct allocation and target, restore the saved file,
append child work, and independently read that work from the child's new
snapshot. Shared-source discovery stays covered. The filter excludes 42
other integration cases.
- `pnpm -r typecheck`, `pnpm build`, `node scripts/check-maps.mjs`, and
`git diff --check` pass. A direct server typecheck also passes after the
final test edit.
- `pnpm test:run` stopped in its first chat shard: 338 passed, one
Discord receiver-lease setup failure, 1,478 outside the shard. The
failing test passes in isolation on both the unchanged baseline and the
fix. Its suite-order failure is not explained by that retry and remains
recorded. The unchanged baseline also fails three other Discord
publication cases in that chat shard, while its next chat shard passes.
This does not reproduce or explain the original lease failure; both
results remain recorded. CI is complete on `e697f6e1b8`: 54 successful
check runs, one successful legacy status, three skipped checks, and one
neutral check. No check is pending or failed. Greptile gives this commit
5/5 with no remaining findings. The security reviewer accepted the
V1-contract explanation; both review threads are resolved.
- Live sandbox acceptance remains unverified. The available test
credentials could not resolve the required sandbox snapshot. The
provider rejected creation before workspace execution, and a scoped
follow-up found no allocation. No live model turn, deployment, or
original-task recovery is claimed.
- Local environment: macOS arm64, Node 26.4.0, pnpm 9.15.4. Native
PostgreSQL startup hit the host semaphore limit; tests use disposable
Docker databases. No shared database was reset.

## Risks

- A bound child can now write after the prior writer releases the
workspace. Incorrect binding or access checks could expose source data.
Regressions cover unbound, private-source, and foreign-company
rejection.
- Concurrent children must not become two writers. A real transaction
race grants exactly one reservation; saved-file tests keep the second
writer blocked until save completes.
- No schema or migration changes. This PR does not change task-creation
inheritance, requested models, credentials, trust, approval gates, or
recovery budgets.

## Model Used

- OpenAI Codex, based on GPT-6. The exact serving model ID and context
window are not exposed in this session. Used reasoning, tool use, code
execution, and browser diagnostics. No sub-agents were used.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass — the targeted workspace
suites pass; the full local chat-suite failure and baseline comparison
are documented above
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
cryppadotta added a commit that referenced this pull request Nov 3, 2026
## Thinking Path

> - Paperclip manages AI agents and their work.
> - A child task can inherit its parent's remote workspace.
> - The remote workspace permits one writer until that writer saves its
files.
> - Reservation reports an active writer as a generic setup failure.
> - The existing shared workspace wait does not cover inherited isolated
workspaces or a race at reservation.
> - This pull request sends verified active writer contention through
the existing scheduled retry path.
> - The child keeps a live execution path while unfinished files remain
protected.

## Linked Issues or Issue Description

**What happened?**

A native sandbox task inherited an isolated remote workspace from its
running parent. Setup failed with `The workspace still has an unfinished
writer or save operation.` The child became blocked before provider
execution and had no scheduled continuation after the parent saved.

**Expected behavior**

The child waits for the active writer through the existing workspace
retry path. It keeps its workspace binding. A stale writer or a stopped
writer with unfinished saves still requires reconciliation.

**Steps to reproduce**

1. Start a native sandbox task with remote workspace storage.
2. Create a child that inherits its isolated workspace or operator
branch while the parent is still writing.
3. Start the child. On the old code, atomic reservation raises a generic
setup failure.

**Paperclip version or commit**

Observed on `410b0e27015495ab8951768b5b0b94727de33785`. Regression
reproduced on source based on
`554a770c6f8e48e327e19f5208b575a5ec5bce30`.

**Deployment mode**

Authenticated managed server, external PostgreSQL, native Codex with a
Daytona sandbox. The failed attempt stopped before runtime selection or
provider startup.

Related: #18611 permits inherited remote bindings. #16371 adds waits for
reused shared execution workspaces. This repair handles active writer
contention at atomic remote reservation. #17156 proposes a separate
change to task workspace inheritance.

## What Changed

- Return a typed conflict with the exact active writer from the remote
reservation owner. Keep company, binding, access, and writer checks in
that transaction.
- Translate a recent running writer into the existing heartbeat
workspace wait. Keep stale, unknown, stopped, dirty, and uncertain save
fences. The writer task lookup uses its primary key.
- Preserve the admitted assignee role across preparation so reassignment
cannot turn an old owner into a guest retry.
- Add PostgreSQL regressions for isolated workspaces, operator branches,
native writer identity, unchanged saved authority, admission after save,
durable retry, Stop, and reassignment before contention reaches the wait
handler.
- Update the development guide and workspace verification recipes.

## Verification

- Red: both inherited isolated/operator preparation cases fail on the
old code. They receive `HttpError(remote_workspace_writer_pending)`
instead of a workspace wait. No provider or allocation starts.
- Green: those same cases pass after the repair. The assembled public
heartbeat cases also pass: one scheduled retry owns the task lock, no
sandbox lease is created, the original writer and saved authority remain
unchanged, and Stop prevents retry promotion.
- Ownership race red/green: changing the assignee during preparation
produced `wasIssueAssignee: false` before the review fix. The same
regression now preserves its original role. A real transaction fault
boundary also reassigns the task after reservation rejects it and before
the wait handler runs; promotion cancels that retry with
`issue_reassigned`.
- Test isolation: an initial combined placement cached the synthetic S3
run-log backend and failed twelve later preparation cases. The assembled
native tests now have their own process. The ordered reproduction and
all four complete affected suites pass after that change: 171 tests,
zero skipped.
- Four additional saved-file lifecycle cases pass against disposable
Docker PostgreSQL 17 with independent filesystem execution and local
object storage. They restore inherited shared, isolated, and
operator-branch files on a new allocation and retain the second-writer
fence. The other 42 cases in that file were outside the selection.
- `pnpm -r typecheck`, `pnpm build`, `node scripts/check-maps.mjs`, and
`git diff --check` pass on the final source.
- The earlier `pnpm test:run` passed all six chat shards: 1,828 tests.
Its remaining general-server phase was interrupted after final-head CI
passed. That local command began before the review fix and is not a
complete local full-suite pass.
- Final head `096235d8fc80033f92d8de1fcfa9835795ba0456`: 54 successful
checks/statuses, three skipped checks, and two neutral checks. None is
pending or failed. All build, typecheck, general/serialized tests,
Runner checks, and eight browser E2E shards pass in
[CI](https://github.com/paperclipai/paperclip/actions/runs/41544310900).
The PR is mergeable with no conflicts.
- Greptile is 5/5 on that exact head. Its ownership finding is resolved
and no review thread remains open. Paperclip Review also reports 5/5
with no findings; its check conclusion is neutral. Its earlier
status-conflict recovery completed through the ordinary review request
path.
- Local environment: macOS arm64, Node 26.4.0, pnpm 9.15.4, isolated
native PostgreSQL and the disposable PostgreSQL 17 lifecycle fixture.
The acquisition boundary is controlled in the focused preparation cases.
No live Codex/Daytona replay is claimed: the local environment and test
configuration lack the required test credentials.
- No deployment, merge, or original task recovery is claimed.

## Risks

- Incorrect contention classification could retry a stopped or
unverified writer. Only a running writer with a same-company task and
recent activity enters the wait path. Stale and terminal dirty cases
retain the conflict.
- Retries must not start another executor or release unsaved files.
Reservation remains atomic. The tests check unchanged writer authority,
no allocation before release, one durable retry, retained binding, Stop,
and reassignment before the conflict is caught.
- No API schema, database migration, provider configuration, model,
credential, trust, or approval changes.

## Model Used

- OpenAI `gpt-6.1-sol` through Codex. The context window size is not
exposed in this session. Used reasoning, tool use, code execution, and
browser diagnostics. No sub-agents were used.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass — targeted and chat results
are recorded above; the full local command was interrupted
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [x] All Paperclip CI gates are green
- [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>

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.

1 participant