Skip to content

fix(j5): reject changed Crew proposal replay requests - #661

Merged
BastiHu merged 8 commits into
fix/181-spawn-replayfrom
fix/316-crew-replay
Oct 21, 2026
Merged

BastiHu merged 8 commits into
fix/181-spawn-replayfrom
fix/316-crew-replay

Conversation

@BastiHu

@BastiHu BastiHu commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Reusing a Crew proposal or seat-addition request key with different arguments returned the first proposal as if it matched. Fixes #316's proposal replay bug.

What changed

Compare retries with the proposal's original stored request, independently of the person's approved roster. Normalize workspace defaults and playbook identity, exclude server-derived persona swaps, and check existing proposals before mutable catalog, playbook, seat-name and capacity validation. Check the stored row after create/admit too, so concurrent first attempts cannot silently return a different request. Replay and launch reuse the same worktree-path normalization; spawn and Crew conflicts share their error wording.

Migration 045 (CrewPlaybookRequestWorkspace) adds the nullable original request workspace to proposal rows; this layer adds no table. Current main resolves playbooks from environment and configured folder libraries, so the selected definition path can be shared by different caller workspaces or change after a local override. New proposals store the normalized caller workspace and replay without re-resolving the live library. Older proposals retain the existing local-path comparison.

This is layer 2, based on #660 (fix/181-spawn-replay). Parent head 7f39d8dc070197730ceb4505a45eaeead8876d13, including current j5/main at 557750d3f9, is merged normally into this branch. Merge #660 first and retarget this PR to j5/main afterward.

Validation

Validated the source published as 12022e74cca17c033d15e20a224f9dc5f342681e:

  • Nine focused suites passed: 181 tests before the new upgrade regression across CrewProposalService, AgentCrewProposalService, Migrations, RequestReplayService, spawnWorkspace, CrewLaunchService, MCP handlers/tools and PlaybookStore.
  • After adding the upgrade regression, all 19 migration tests passed. The new case starts at merged migration 043, verifies replay table creation at 044 and the workspace column at 045, and verifies a safe repeat run.
  • The real folder-library regression verifies two workspaces resolving the same library file, refusal of changed-workspace reuse, identical replay after a local override, and replay after the library source is removed. It uses the actual PlaybookLibrary resolver.
  • Coverage includes identical/mismatched retries, edited/approved/declined proposals, wrong-Crew requests, persona/playbook changes, concurrent first attempts at capacity, validation failures and SQLite close/reopen after a lost response.
  • Changed-file lint, formatting and server typecheck passed. Typecheck emitted existing suggestion diagnostics but no errors.

Live testing

No live server or provider turns were run. Verification uses handler/service tests with real SQLite persistence and temporary filesystem libraries, plus controlled launch fakes. No UI changes.

Limits

A pre-045 proposal that selected a nonlocal library path cannot prove its original caller workspace, so its replay is visibly refused; use a fresh request key for new work.

The stale stop_agent / stop_crew receipt behavior described in #316's comment is a separate mechanism and remains unchanged. Seat additions retain the existing visible refusal when an omitted Crew target becomes ambiguous or the Crew is no longer commanded. A replay does not recompute the optional fresh playbook-validation summary.

#638 has merged into j5/main, occupying migration IDs 039–043. This stack now preserves those IDs and uses 044 for parent replay storage and 045 for the original Crew playbook request workspace. Migration upgrade tests cover the merged schema; there is no remaining numbering overlap with #638.

Checklist

  • One concern: Crew proposal replay safety
  • Tests cover the changed backend behavior
  • UI evidence — not applicable; no UI changes
  • Live-testing limits stated above
  • Upstream-owned edits — none in this layer
  • Upstream product decision — not applicable
  • Surfaces: shared backend service, MCP entry points, original/approved proposals and replay/concurrency paths checked
  • Product/user docs — no feature-definition change

Implemented with GPT-6.1-Sol in Codex; parent-layer fixes and prior review by Claude Opus 5.5 in Claude Code.

Compare immutable original proposal fields before live validation and again after concurrent create/admit. Identical retries retain the original proposal after approval, decline, catalog changes and partial failures.

Keep the existing stable ids and admission rules. Replay omits the optional live-validation playbook summary. Existing ambiguous or archived crew target selection still refuses visibly.

Co-Authored-By: GPT-6.1-Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BastiHu BastiHu self-assigned this Oct 19, 2026
@vercel

vercel Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
j5-code Ready Ready Preview Oct 21, 2026 1:19pm UTC

Request Review

@github-actions github-actions Bot added the vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. label Oct 19, 2026
@github-actions github-actions Bot added the size:L 100-499 effective changed lines (test files excluded in mixed PRs). label Oct 19, 2026

@tyler-barton-horizon tyler-barton-horizon left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking review. The replay ordering and the post-create/admit re-check look right to me, and the identical/mismatched/concurrent coverage is solid. A few simplification and consistency notes are inline; none of them block merging.

);
} else {
const stem = name.endsWith(".yaml") ? name.slice(0, -5) : name;
// Older rows can prove a workspace-local path, but cannot prove a library workspace.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking: I don't think requestWorkspaceRoot adds anything to the comparison. PlaybookStore.definitionPathFor is just path.resolve(workspaceRoot, ".j5/playbooks", ${stem}.yaml), so a stored definitionPath already pins exactly one resolved workspace root (and stem). The legacy branch here, which recomputes the path and compares { path }, is therefore equivalent for new rows as well.

If that's right, you could drop the column, migration 040, the optional CrewPlaybookRef.requestWorkspaceRoot field and the two-shape playbook key in proposalRequest, and always compare the resolved path. Nothing "library" resolves elsewhere today, so the comment about a library workspace reads as hypothetical. If a non-local lookup is planned, it would help to say so here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The premise changed after merging current main through #660: PlaybookStore now resolves nonlocal libraries. Retained requestWorkspaceRoot and migration 040. The real PlaybookLibrary regression in f6c916d proves that two caller workspaces can select the same definitionPath, changed-workspace reuse must conflict, and identical replay survives a local override or removal of the library source. The normalized caller workspace preserves original intent without consulting a changed catalog. All 179 focused tests passed.


export default Effect.gen(function* () {
const sql = yield* SqlClient.SqlClient;
yield* sql`ALTER TABLE j5_agent_crew_proposal ADD COLUMN playbook_request_workspace_root TEXT`;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking: the PR description says "No new table or migration is added", but this adds migration 040. Can you update the description? It's also worth noting this next to the existing 039 / #638 overlap caveat, because 040 will have to be renumbered along with it when the stack is reconciled. (If the column turns out to be unnecessary, see the comment on CrewProposalService.ts, this file goes away.)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed the description. It explicitly names migration 040 (CrewPlaybookRequestWorkspace), explains the original request workspace needed for current nonlocal libraries, and states that this layer adds no table. The integration caveat covers inherited 039 and child 040.

workspace?.type === "worktree"
? { ...workspace, startFromOrigin: workspace.startFromOrigin ?? false }
: workspace?.type === "existing_worktree"
? { ...workspace, worktreePath: workspace.worktreePath.replace(/[\\/]+$/, "") }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking: this regex duplicates worktreePathKey in spawnWorkspace.ts:52, which the launcher already uses to match worktree paths. Exporting and reusing it would keep replay equality and launch-time matching from drifting apart if that normalization ever changes (for example, to also path.resolve).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in the source published as f6c916d. Exported and reused the existing worktreePathKey from spawnWorkspace.ts so replay comparison and launch matching share normalization. Focused workspace/launcher tests pass as part of the 179-test run.

) {
if (requestDigest(proposalRequest(original)) !== requestDigest(proposalRequest(request)))
return yield* new CrewProposalRequestError({
detail: `client_request_id is already bound to a different request for proposal ${original.id}${original.crewInstanceId === null ? "" : ` and crew ${original.crewInstanceId}`}.`,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: this detail/nextStep copy repeats the wording of RequestReplayConflictError.message in RequestReplayService.ts. A shared helper or constant would keep the two replay-conflict messages from diverging, since agents see both.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in the source published as f6c916d. Both conflict paths use requestReplayConflict(target) from RequestReplayService.ts. Regression assertions cover the exact agent-facing message; the 179 focused tests passed.

@bryantderosier bryantderosier left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reconciled review from two independent reviewers: OpenAI GPT-6.1-Sol and Anthropic Claude Opus 5.5. No blocking code defect was confirmed in this incremental layer. Approving base 839b7b0 -> head e89bff4; both were rechecked before submission.

Integration advisory: this approval covers the reviewed stack base. #660 remains blocked by its separate review and must land first; recheck this layer after rebasing/retargeting. Migration 040 overlaps open #638's 040_Links (and inherited 039 overlaps that PR too). Coordinate migration IDs with whichever history lands first; see inline comment. The overlap with an unmerged branch is an integration constraint, not a runtime defect against this base.

Please refresh the PR description: it says no migration was added, but this head adds 040_CrewPlaybookRequestWorkspace. The validation section also cites older tips and does not describe the e89bff4 behavioral change.

Validation reported by reviewers: OpenAI ran 4 focused files / 68 passing tests and a pinned diff whitespace check; Anthropic ran 9 focused files / 111 passing tests and a passing server typecheck. These are separate runs with overlapping coverage, not an aggregate unique-test count. No live server/provider turns or browser testing occurred. No additional runtime findings survived reconciliation.

Comment thread apps/server/src/j5/a2a/Migrations.ts Outdated
[37, "PersonNames", Migration0037],
[38, "OpenLinkJoins", Migration0038],
[39, "RequestReplay", Migration0039],
[40, "CrewPlaybookRequestWorkspace", Migration0040],

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Integration advisory, nonblocking against this base: migration ID 40 is also used by open #638 for 040_Links; inherited ID 39 overlaps its 039_PeopleAndLevels. The migration tracking table uses numeric IDs, so carrying both histories without reconciling numbering can skip required schema changes. Whichever branch lands second must reconcile its migration IDs against the merged history and rerun migration tests. Please also correct the PR body's statement that no migration was added.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Documented both overlapping IDs and corrected the migration claim in the PR body. Current merged main ends at 038, so 039/040 have no present collision; #638 remains open with 039–043. Whichever workstream merges second must renumber against the actual merged history and rerun migration tests. Renumbering ahead now is unsafe because the migrator skips IDs at or below the latest applied migration. No speculative renumbering was made.

@BastiHu

BastiHu commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

@bryantderosier Addressed your review feedback. The description now explicitly names migration 040 and its purpose, records the current validation head, and documents the merge-order requirement for migrations 039/040 versus #638.

Current head 31639e541c includes the final #660 fixes (0fff0c5719) through a normal merge. All 181 focused tests passed, plus scoped lint/formatting and server typecheck. No live provider/runtime testing. This remains based on #660; it should land first, followed by retargeting and migration reconciliation against the history that actually lands. The integration advisory also has an inline reply.

@BastiHu
BastiHu merged commit 1a02387 into fix/181-spawn-replay Oct 21, 2026
29 checks passed
@BastiHu
BastiHu deleted the fix/316-crew-replay branch October 21, 2026 15:43
BastiHu added a commit that referenced this pull request Oct 27, 2026
* fix(j5): reject changed spawn replay requests

Co-Authored-By: GPT-6.1-Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(j5): verify spawn replay failures and concurrent retries

Restore complete live-caller shell fixtures and assert injected failure causes. Keep identical and mismatched concurrent retries as distinct cases, and authorize persisted children before replaying create.

Integration note: RequestReplay migration 039 conflicts with pending #638 migrations 039–042; reconcile numbering against main before publication.

Co-Authored-By: GPT-6.1-Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(j5): address spawn replay review comments

Keyless spawns no longer write replay rows nobody can retry. The replay
service declares its interface inline, and check no longer returns an
unused boolean. Both replay mode checks share one message; the early one
stays because it is the only check an unbound legacy agent reaches.
Replay rows record created_at, and the spawn tool description says that
any change under a reused client_request_id is refused.

* fix(j5): refuse bad spawn attachments before binding the key

Duplicate attachment ids, attachment limits and non-pending references
are refused before the client_request_id is bound, so a corrected list
can be retried under the same key instead of being refused as a changed
request. A replay-store SQL failure now tells the caller to retry the
same key, keeping the inspect-target guidance for real conflicts. The
agent tools doc states the whole-request binding.

* fix(j5): reject changed Crew proposal replay requests (#661)

* fix(j5): reject changed crew proposal replay requests

Compare immutable original proposal fields before live validation and again after concurrent create/admit. Identical retries retain the original proposal after approval, decline, catalog changes and partial failures.

Keep the existing stable ids and admission rules. Replay omits the optional live-validation playbook summary. Existing ambiguous or archived crew target selection still refuses visibly.

Co-Authored-By: GPT-6.1-Sol <noreply@openai.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix(server): replay crew proposals before playbook lookup

* fix(j5): simplify crew proposal replay comparison

* fix(j5): preserve replay workspace for playbook libraries

* test(j5): verify crew replay against playbook libraries

---------

Co-authored-by: GPT-6.1-Sol <noreply@openai.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

* fix(j5): validate upload metadata before accepting spawns

* refactor(j5): own direct spawn acceptance in domain service

* fix(j5): complete replay recovery and canonical contracts

* fix(j5): refuse cross-workspace legacy retries before binding

---------

Co-authored-by: GPT-6.1-Sol <noreply@openai.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 12022e74 Deployed Oct 21, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L 100-499 effective changed lines (test files excluded in mixed PRs). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants