Skip to content

Commit 62f20ef

Browse files
Merge branch 'main' into fix/zoo-gateway-models-session-cache
2 parents a5d5e62 + 05d01f3 commit 62f20ef

13 files changed

Lines changed: 458 additions & 118 deletions

‎.github/workflows/label-pr-review-state-fork-review-followup.yml‎

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,43 +52,44 @@ jobs:
5252
return;
5353
}
5454
55-
// Same-repository review runs already ran with a privileged
56-
// token and wrote their labels; only fork runs need the
57-
// follow-up.
58-
if (run.head_repository && run.head_repository.fork === false) {
59-
core.info('Ignoring same-repository pull_request_review run');
60-
return;
61-
}
62-
63-
// Resolve which PRs the completed run targeted. Fork runs
64-
// backfill pull_requests empty, so fall back to the exact head
65-
// owner, branch, and SHA lookup used by the resolve job of
66-
// label-pr-review-state.yml. Keep both copies in sync.
55+
// GitHub reports the base repository as head_repository on
56+
// every pull_request_review run, fork PR or not (issue
57+
// #2133), so the payload cannot tell fork from same-repo
58+
// runs. Dispatching for a same-repo PR is idempotent: the
59+
// reconciliation writes the same labels, and its completion
60+
// carries event 'workflow_dispatch', which the guard above
61+
// filters out.
62+
//
63+
// Resolve which PRs the completed run targeted. Review runs
64+
// backfill pull_requests empty for fork PRs, and the head
65+
// owner is not recoverable from head_repository, so the
66+
// fallback lists open PRs and matches the exact head branch,
67+
// SHA, and base repository. The workflow_run branch of
68+
// label-pr-review-state.yml keeps an owner-and-branch query
69+
// instead: its runs are CI runs triggered by pull_request,
70+
// whose head_repository is the real fork.
6771
let prNumbers = [];
6872
if (run.pull_requests?.length > 0) {
6973
prNumbers = run.pull_requests.map(pr => pr.number);
70-
} else {
71-
const headOwner = run.head_repository?.owner?.login;
72-
if (headOwner && run.head_branch && run.head_sha) {
73-
const candidates = await github.paginate(github.rest.pulls.list, {
74-
owner,
75-
repo,
76-
state: 'open',
77-
head: `${headOwner}:${run.head_branch}`,
78-
per_page: 100,
79-
});
80-
const baseRepository = `${owner}/${repo}`.toLowerCase();
81-
prNumbers = candidates
82-
.filter(pr =>
83-
pr.head?.sha === run.head_sha &&
84-
pr.base?.repo?.full_name?.toLowerCase() === baseRepository
85-
)
86-
.map(pr => pr.number);
87-
core.info(
88-
`Resolved workflow_run ${run.id ?? '(unknown)'} to ` +
89-
`${prNumbers.length} PR(s) by exact head owner, branch, and SHA`
90-
);
91-
}
74+
} else if (run.head_branch && run.head_sha) {
75+
const candidates = await github.paginate(github.rest.pulls.list, {
76+
owner,
77+
repo,
78+
state: 'open',
79+
per_page: 100,
80+
});
81+
const baseRepository = `${owner}/${repo}`.toLowerCase();
82+
prNumbers = candidates
83+
.filter(pr =>
84+
pr.head?.sha === run.head_sha &&
85+
pr.head?.ref === run.head_branch &&
86+
pr.base?.repo?.full_name?.toLowerCase() === baseRepository
87+
)
88+
.map(pr => pr.number);
89+
core.info(
90+
`Resolved workflow_run ${run.id ?? '(unknown)'} to ` +
91+
`${prNumbers.length} PR(s) by exact head branch, SHA, and base repository`
92+
);
9293
}
9394
9495
// Each dispatch starts a privileged workflow_dispatch run of the

‎.github/workflows/label-pr-review-state.yml‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,13 @@ jobs:
138138
// number in the payload; sweep triggers (hourly schedule, pushes to
139139
// main) list every open PR; workflow_run events use the run's
140140
// associated PRs, with a fork-safe backfill by exact head owner,
141-
// branch, and SHA when GitHub left pull_requests empty. Keep the
142-
// backfill in sync with label-pr-review-state-fork-review-followup.yml.
141+
// branch, and SHA when GitHub left pull_requests empty. The
142+
// workflows listed in workflow_run trigger on pull_request, whose
143+
// head_repository is the real fork, so the owner-and-branch query
144+
// is safe here. The follow-up workflow's copy of this backfill
145+
// matches by head branch, SHA, and base repository instead: its
146+
// pull_request_review runs report the base repository as
147+
// head_repository (issue #2133).
143148
let prNumbers = [];
144149
if (context.payload.pull_request?.number) {
145150
prNumbers = [context.payload.pull_request.number];

‎docs/architecture/task-lifecycle-target-architecture.md‎

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,28 @@ type RunState = {
190190
generation: number
191191
stream: Stream
192192
ask: Ask
193+
turn: Turn
193194
latches: Latches
194195
lastCompletionAskTs?: number
195196
}
196197

198+
type Turn = {
199+
waitingForFirstChunk: boolean
200+
toolRejected: boolean
201+
toolUsed: boolean
202+
toolFailed: boolean
203+
streamReadComplete: boolean
204+
}
205+
197206
type RunEvent =
198207
| { tag: "initialized" }
208+
| { tag: "turnStarted" }
209+
| { tag: "firstChunkAwaitStarted" }
210+
| { tag: "firstChunkAwaitEnded" }
211+
| { tag: "toolRejected" }
212+
| { tag: "toolUsed" }
213+
| { tag: "toolFailed" }
214+
| { tag: "streamReadCompleted" }
199215
| { tag: "streamStarted" }
200216
| { tag: "streamCleanupFinished" }
201217
| { tag: "streamEnded" }
@@ -229,25 +245,32 @@ Queued user input is out of scope for the kernel. The queued-input bugs (#1308,
229245
7. Abort drain. The chunk loop sees `abort`. If the task is not abandoned, the loop calls `abortStream` (`Task.ts:3492`). Only a non-abandoned abort reaches this call, for example a checkpoint-restore delete or a dispose. `abortStream` sets `didFinishAbortingStream` (`Task.ts:3225`). The `finally` block clears `isStreaming` (`Task.ts:3756`).
230246
8. Stream failure. A stream error without `abort` also calls `abortStream("streaming_failed")` (`Task.ts:3714`), which sets `didFinishAbortingStream` (`Task.ts:3225`). Then the loop retries. It does not abort. The per-request reset block (`Task.ts:3228-3245`) does not reset `didFinishAbortingStream`. Only `resumeAfterDelegation` resets it (`Task.ts:2884`). So the field stays true across later requests (race R-1 below).
231247
9. Completion. `attempt_completion` asks `completion_result` during the turn (`AttemptCompletionTool.ts:221`). The ask is usually still pending after the stream ends. On accept the task ends. On feedback the loop continues.
232-
10. New instance. `reopenParentFromDelegation` builds a new instance and calls `resumeAfterDelegation` (`ClineProvider.ts:4357, 4404`). Latches are per instance. No path reuses an aborted instance. The resets at `Task.ts:2881-2886` write the default values on the new instance.
248+
10. New instance. `reopenParentFromDelegation` builds a new instance and calls `resumeAfterDelegation` (`ClineProvider.ts:4357, 4404`). Latches are per instance. No path reuses an aborted instance. `resumeAfterDelegation` no longer resets the latches. It resets only the stream fields (`Task.ts:2884-2886`).
233249

234250
#### Transitions
235251

236252
Each event has a guard and an effect. If the guard fails, the event returns `rejected` with the state unchanged. An effect changes only the fields it names.
237253

238-
| Event | Guard | Effect |
239-
| ----------------------- | ------------------------------------------------------------------ | --------------------------------------------------------------------------------------------- |
240-
| `initialized` | phase is uninitialized | phase = running |
241-
| `streamStarted` | phase is running, stream is none | generation + 1, stream = live(generation, cleanupFinished false), lastCompletionAskTs = empty |
242-
| `streamCleanupFinished` | stream is live | stream.cleanupFinished = true |
243-
| `streamEnded` | stream is live | stream = none |
244-
| `askStarted` | phase is running, abort is false | ask = the new ask. lastCompletionAskTs = its askTs if it is a completion ask, else empty |
245-
| `askSettled` | none | if ask.askTs equals the event askTs, ask = none. Else no change |
246-
| `completionAccepted` | phase is running, abort is false, askTs equals lastCompletionAskTs | phase = completed, ask = none |
247-
| `reasonSet` | none | if reason is empty, reason = the new reason. Else no change |
248-
| `abortRequested` | none | abort = true. If the event has abandoned true, abandoned = true |
249-
| `abandonRequested` | abort is true | abandoned = true |
250-
| `disposeRequested` | none | abort = true, disposed = true |
254+
| Event | Guard | Effect |
255+
| ------------------------ | ------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
256+
| `initialized` | phase is uninitialized | phase = running |
257+
| `turnStarted` | none | toolRejected, toolUsed, toolFailed, streamReadComplete = false. waitingForFirstChunk unchanged |
258+
| `firstChunkAwaitStarted` | none | turn.waitingForFirstChunk = true |
259+
| `firstChunkAwaitEnded` | none | turn.waitingForFirstChunk = false |
260+
| `toolRejected` | none | turn.toolRejected = true |
261+
| `toolUsed` | none | turn.toolUsed = true |
262+
| `toolFailed` | none | turn.toolFailed = true |
263+
| `streamReadCompleted` | none | turn.streamReadComplete = true |
264+
| `streamStarted` | phase is running, stream is none | generation + 1, stream = live(generation, cleanupFinished false), lastCompletionAskTs = empty |
265+
| `streamCleanupFinished` | stream is live | stream.cleanupFinished = true |
266+
| `streamEnded` | stream is live | stream = none |
267+
| `askStarted` | phase is running, abort is false | ask = the new ask. lastCompletionAskTs = its askTs if it is a completion ask, else empty |
268+
| `askSettled` | none | if ask.askTs equals the event askTs, ask = none. Else no change |
269+
| `completionAccepted` | phase is running, abort is false, askTs equals lastCompletionAskTs | phase = completed, ask = none |
270+
| `reasonSet` | none | if reason is empty, reason = the new reason. Else no change |
271+
| `abortRequested` | none | abort = true. If the event has abandoned true, abandoned = true |
272+
| `abandonRequested` | abort is true | abandoned = true |
273+
| `disposeRequested` | none | abort = true, disposed = true |
251274

252275
Transition notes:
253276

@@ -324,6 +347,18 @@ The `didFinishAbortingStream` getter is false after the stream ends. The only re
324347

325348
The turn sub-machine holds five within-turn fields: `isWaitingForFirstChunk`, `didRejectTool`, `didAlreadyUseTool`, `didToolFailInCurrentTurn`, and `didCompleteReadingStream`. A turn is one request iteration of the loop. It starts at the per-request reset block (`Task.ts:3228-3245`), before `streamStarted`. It ends when the next iteration starts. It is independent of the stream region, because the loop writes these fields after the stream ends (`Task.ts:3768, 3810, 3830, 4029`).
326349

350+
Turn events have no guard. The loop and the tools write these fields in every phase, after abort, and after the stream ends. No other event changes the turn. Event and field names map to the `Task` fields as follows.
351+
352+
| Kernel field (event) | `Task` field |
353+
| ------------------------------------------------------- | -------------------------- |
354+
| `waitingForFirstChunk` (`firstChunkAwaitStarted/Ended`) | `isWaitingForFirstChunk` |
355+
| `toolRejected` (`toolRejected`) | `didRejectTool` |
356+
| `toolUsed` (`toolUsed`) | `didAlreadyUseTool` |
357+
| `toolFailed` (`toolFailed`) | `didToolFailInCurrentTurn` |
358+
| `streamReadComplete` (`streamReadCompleted`) | `didCompleteReadingStream` |
359+
360+
`turnStarted` does not reset `waitingForFirstChunk`. The legacy reset block does not clear `isWaitingForFirstChunk`, and `attemptApiRequest` clears it. If the chunk loop breaks on the first chunk, the generator never resumes and the flag stays true. The kernel keeps that behavior, so RSK-10 and RSK-16 do not change graceful-abort timing at `ClineProvider.ts:3641`.
361+
327362
#### External writers
328363

329364
`ClineProvider` writes `abortReason` (`:3572`) and `abandoned` (`:3588`) directly. It calls `abortTask` at `:631` and `:1389`. `checkpointRestoreHandler` calls `abortTask` (`:34`). RSK-06 routes every one of these writes through events before any read flips.

0 commit comments

Comments
 (0)