Skip to content

fix: cancel selected-workspace PTC across processes - #196

Open
danny-avila wants to merge 11 commits into
mainfrom
danny-avila/byom-ptc-cancellation
Open

fix: cancel selected-workspace PTC across processes#196
danny-avila wants to merge 11 commits into
mainfrom
danny-avila/byom-ptc-cancellation

Conversation

@danny-avila

@danny-avila danny-avila commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • persist replay cancellation targets and deliver cancellation across API/worker processes
  • use one shared Redis cancellation subscriber per service process instead of per-request polling
  • rebuild terminally disconnected subscribers with bounded retry and durable-marker reconciliation
  • fence and remove jobs across enqueue, waiter-registration, and activation races
  • stop cancellation-delay and long-poll transports promptly once execution completes
  • preserve child-reported pre-dispatch mutation certainty so failed input setup does not quarantine an untouched workspace
  • reject cancellation observed during asynchronous result cleanup before BullMQ can commit success
  • reference-count shared credential rotation so cancelling one execution lane cannot fail another

Scale and reliability

  • constant subscriber count per process, independent of concurrent runs
  • durable short-lived cancellation markers close publish/subscribe and cross-replica races
  • no per-job cancellation polling while connected
  • shared credential rotation coalesces network and persistence work across concurrent lanes
  • timers, subscribers, queued jobs, waiters, and metrics are released on terminal paths
  • same-workspace mutation fencing remains serialized; independent workspace slots remain concurrent

Verification

  • 18 focused cancellation tests
  • 59 focused worker lifecycle and concurrency tests on the built package
  • Code package and service builds
  • CI green except the still-running arm64 image job
  • exact-head local LibreChat → Agents PTC → Code API → native SRT acceptance:
    • two paired workers and isolated selected workspaces
    • Ask, Accept edits, and Full access policy paths
    • fresh always-apply skill file staged privately and consumed through PTC
    • durable project mutation with no skill namespace leakage
    • worker isolation and offline fail-closed behavior

Depends on #195.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head a937bff

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-14T15:25:56.279779Z ad14f28 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a937bffbaf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread service/src/service/programmatic-router.ts Outdated
Comment thread service/src/service/programmatic-router.ts Outdated
Comment thread service/src/job-cancellation.ts Outdated
Comment thread service/src/service/programmatic-router.ts
Comment thread service/src/programmatic-cancellation.ts
@danny-avila
danny-avila force-pushed the danny-avila/byom-ptc-cancellation branch from a937bff to a75dfad Compare September 14, 2026 09:53
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head a75dfad. This is the cancellation layer restacked on the corrected #195 head. Focused cancellation tests and a real local abort prove ~1s termination, no late mutation, and immediate workspace reuse.

@danny-avila
danny-avila force-pushed the danny-avila/byom-ptc-cancellation branch from a75dfad to e45a407 Compare September 14, 2026 09:55
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head e45a407. Restacked cancellation layer on #195 exact head e18c379.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: e45a40759e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head beb5ad7. Full local LibreChat → Agents → Code API → worker testing exposed and now covers prompt cancellation-watch teardown; focused worker tests pass.

@danny-avila
danny-avila force-pushed the danny-avila/byom-ptc-cancellation branch from beb5ad7 to 503de80 Compare September 14, 2026 10:16
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head 503de80. Supersedes the prior review request: the regression coverage now closes both cancellation-watch teardown races, before and during the long-poll.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: beb5ad7948

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 503de80c55

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread service/src/service/programmatic-router.ts Outdated
Comment thread service/src/job-cancellation.ts Outdated
@danny-avila
danny-avila force-pushed the danny-avila/byom-ptc-cancellation branch from 503de80 to 09180cd Compare September 14, 2026 10:30
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head 09180cd. Full local stack found two lifecycle classes beyond request cancellation: cancellation-watch teardown races and loss of pre-dispatch mutation certainty across child IPC. Both are fixed with focused regressions and live failure/recovery verification.

@danny-avila
danny-avila force-pushed the danny-avila/byom-ptc-cancellation branch from 09180cd to aa5882a Compare September 14, 2026 10:33
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head aa5882a. Final local acceptance head: cancellation completes in ~1s with no late mutation and immediate reuse; pre-dispatch transport failures reject without quarantine; uncertain post-dispatch failures remain fail-closed and expose their local cause.

@danny-avila danny-avila changed the title Cancel BYOM PTC jobs across API and worker processes fix: cancel selected-workspace PTC across processes Sep 14, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: aa5882ae91

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila
danny-avila force-pushed the danny-avila/byom-ptc-cancellation branch from aa5882a to 01749d1 Compare September 14, 2026 10:57
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head 01749d1

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head d017f3e

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d017f3ed06

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread service/src/service/programmatic-router.ts
Comment thread packages/code/src/worker.ts Outdated
Comment thread service/src/service/programmatic-router.ts Outdated
Comment thread service/src/job-cancellation.ts
@danny-avila
danny-avila force-pushed the danny-avila/byom-ptc-cancellation branch from d017f3e to dd3d293 Compare September 14, 2026 11:27
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head dd3d293968c748e704c2abfe9dca5f63e9fb555d

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dd3d293e41

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread service/src/workers.ts
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head 9adede8. Please verify the four prior distributed-cancellation findings: external cancellation now wakes the original waiter through the process-wide registry; retryable cancellation bodies stay abortable; cancellation targets are attached before enqueue so failed admission cannot orphan runnable work; and reconnect reconciliation retries with bounded backoff. Also verify the bounded credential-refresh settlement drain.

@danny-avila
danny-avila force-pushed the danny-avila/byom-ptc-cancellation branch from 9adede8 to c8876d1 Compare September 14, 2026 11:59
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review exact head c8876d1. The post-finalization cancellation commit barrier addresses the exact-head P2; all prior findings remain resolved. Focused service/package tests, builds, and local real-worker cancellation/concurrency canaries pass.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c8876d1306

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread service/src/job-cancellation.ts
Comment thread service/src/job-cancellation.ts
Comment thread service/src/job-cancellation.ts
Comment thread service/src/workers.ts Outdated
Comment thread packages/code/src/worker.ts
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review exact current head 5c512a7 and confirm the reviewed commit.

All four latest findings are addressed as one outcome-lifecycle fix. Enqueue, subscription and completion failures recover a durable winning result. Late Stop retains its principal-bound target tombstone through the existing TTL. Subscriber shutdown disconnects without awaiting an offline startup. Commitment checks the absolute producer deadline atomically with Redis TIME, instead of retrospectively rejecting a successful commit whose acknowledgement arrived late; both delayed-dispatch and delayed-ack tests pass. Result/marker publication uses one MSET write to avoid partial OOM publication.

The wider audit also clamps worker budgets to the producer absolute deadline across config drift, owns completion rejections before subscription awaits, and memoizes cancellation fencing so cleanup does not duplicate a successful Redis write. Focused real Redis tests cover the transitions and a local LibreChat + native SRT worker acceptance run is being repeated on this exact head with physical PID and delayed-write Stop assertions. Please inspect the shared invariants and any remaining alternate failure path.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

Final local acceptance passed on 5c512a7 after rebuilding Code API. Real LibreChat + local Agents SDK integration + Redis/Mongo + two native SRT workers, all on isolated ports; deterministic model only, actual tools and filesystem effects.

Verified: physical create/read/edit persistence, Ask/Reject/Accept edits/Full access, reload persistence, workspace-bound PTC and private skill inputs, worker isolation, and offline fail-closed behavior. Both command and PTC Stop tests first verified a live shell PID, clicked the real UI Stop control, verified that PID disappeared within five seconds, waited beyond the delayed mutation time and confirmed no late file was written, then reused the workspace successfully. One focused E2E scenario passed in about 1.3 minutes. No hosted deployment or existing services were changed.

The earlier real-SRT speculative replay canary also passed with exactly one network POST and one workspace write. A separate real Redis check registered 64 targets with one subscriber, cancelled 32 and interrupted none of the others (an isolation check, not a production-capacity claim). Full suites are left to CI; local checks were focused.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c512a7181

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread service/src/service/programmatic-router.ts Outdated
Comment thread service/src/workers.ts Outdated
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review exact head a5b528f and confirm the reviewed commit.

Both latest findings are addressed by deepening the shared outcome interface. Fencing now returns a discriminated cancelled/expired/completed outcome, with the winning result in the same atomic Redis response. Enqueue, subscription, completion and disconnect recovery consume that snapshot without follow-up GETs. The normal Stop route requests only the small decision, not the result body. Initial worker result recovery uses one MGET snapshot as well.

Jobs carry the producer cancellation retention requirement; completion uses the larger local/producer retention. Late Stop atomically renews completion evidence to cover the renewed request tombstone, using millisecond precision to avoid rounded-TTL gaps. Focused real Redis tests cover connection loss after the decision, immediate recovery without a lost queue event, timeout configuration drift, and subsecond retention renewal. Local end-to-end verification will be repeated on this exact head.

The previous immutable outcome/deadline and lost-reply invariants remain covered. Please audit any remaining lifecycle boundary as a whole rather than suggesting independent signal snapshots after a durable outcome has already won.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

Final local acceptance passed again on exact head a5b528f. Real LibreChat + locally linked Agents SDK + Code API + Redis/Mongo + native SRT workers, isolated non-default ports, deterministic model responses only. Physical create/read/edit persistence, approvals, workspace-bound PTC/private skills, worker isolation and offline fail-closed checks passed. Both command and PTC Stop verified a live shell PID, killed it within five seconds, prevented the delayed write after waiting past its scheduled time, and allowed workspace reuse. One focused E2E scenario passed in 1.3 minutes; temporary services were cleaned up. No hosted deployment or existing workspaces changed.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5b528f8ab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread service/src/workers.ts
Comment thread service/src/job-cancellation.ts
Comment thread service/src/job-cancellation.ts Outdated
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review exact head b75bbe1. Confirm that commit in your result.

All three findings are fixed together at the outcome boundary. Selected native workspace jobs now map and durably commit their result inside the existing bridge sessionResultFinalizer, before the bridge clears the mutation fence, regardless of whether egress restoration is needed. Failure or ambiguity there leaves the root quarantined. A successful committed handoff remains successful through later Stop, egress revocation, or bridge cleanup failure. No separate post-handoff signal check can overwrite that result.

Attached request tombstones no longer renew on Stop at all, removing the split renewal window; admission retention bounds the mapping. Deterministic result decoding/validation is outside the Redis transport retry loop. Real Redis regressions cover handoff completion versus cancellation/quarantine, missing and corrupt results with exactly one attempt, and interrupted split renewal. 26 focused Redis/bridge tests plus 23 registry tests pass. The actual local LibreChat + Code API + native SRT worker acceptance just passed again, including physical command and PTC Stop/no-late-write checks, files, approvals and private skills. Please audit these shared invariants and remaining alternate transitions.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b75bbe11d3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread service/src/workers.ts Outdated
@danny-avila

Copy link
Copy Markdown
Collaborator Author

Final post-commit local verification passed on b75bbe1 after rebuilding Code API. The real LibreChat + SDK integration + native SRT worker acceptance passed again in 1.3 minutes, including verified live PIDs before UI Stop, PID termination within five seconds, no delayed file writes, and subsequent workspace reuse for both commands and PTC. Files, approvals, private skills, isolation, reload and offline fail-closed checks passed. Separate real-SRT speculative-network regression passed too. All services used disposable identities and non-default ports; existing deployments/workspaces were untouched.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please review exact head ad14f28 and confirm the reviewed commit.

The stalled-job redelivery finding is fixed at admission as well as settlement. Before any sandbox work, one atomic Redis operation returns the cached committed result or acquires a once-only execution claim. Duplicate processors and ambiguous/lost claim replies cannot authorize another execution; the bounded claim is retained through the producer/local cancellation horizon. The claim shares the cancellation decision transaction, so cancel-before-start fails closed.

commitJobResult now distinguishes committed, cancelled and already_completed. An existing completion cannot be attributed to a second mutation handoff: the native bridge finalizer throws and quarantines that root. The original durable result is never overwritten. Real Redis tests cover concurrent claims (exactly one execution), lost claim ACK, pre-cancellation, missing cached payload, duplicate handoff quarantine and preserving the first result. 23 outcome tests plus 30 registry/request tests pass; service build passes with only existing unrelated warnings. Final local LibreChat/native-SRT acceptance is being repeated on this head. Please inspect remaining lifecycle invariants.

@danny-avila

Copy link
Copy Markdown
Collaborator Author

Final local acceptance and real-SRT speculative replay canary both pass on ad14f28. Real LibreChat, locally linked SDK, Code API, Redis/Mongo and native SRT workers on disposable non-default ports. Both command and PTC Stop verified live shell PIDs, termination within five seconds, absence of delayed writes after their scheduled time, and workspace reuse. File persistence, approval modes, private skills, worker isolation, reload and offline failure checks pass. Temporary services cleaned up; no hosted deployment or existing workspace changed.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ad14f28ad0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread service/src/workers.ts
@danny-avila

Copy link
Copy Markdown
Collaborator Author

@codex review

Please re-review exact unchanged head ad14f28. All valid findings are fixed, CI is fully green, and final real local LibreChat/Code API/native-SRT acceptance passes.

The last finding is disproved by source and real Redis failure injection. In enqueueForActiveIncarnation, workspaceQuarantineKey is KEYS[7], created by SET key assignmentId with NO TTL. Assignment/queue/deadline/receipt expiry does not expire that fence. A failed SET that would relabel it quarantined leaves the original persistent pending fence blocking reuse. The test acknowledged and fulfilled a native assignment, injected failure into the quarantine eval, waited beyond the deadline, and obtained PTTL=-1 both before and after; a new dispatch was rejected WORKSPACE_QUARANTINED. Detailed evidence is in discussion_r4006669482. No code change was needed.

Please confirm the exact-head result after accounting for that persistent fence, and report only additional actionable findings with a demonstrated lifecycle path.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: ad14f28ad0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danny-avila
danny-avila force-pushed the danny-avila/byom-ptc-cancellation branch from ad14f28 to e8b7b34 Compare September 14, 2026 18:04
@danny-avila
danny-avila removed this pull request from stack #197 September 14, 2026 18:08
@danny-avila
danny-avila changed the base branch from danny-avila/byom-workspace-ptc to main September 14, 2026 18:08
@danny-avila danny-avila reopened this Sep 14, 2026
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