Skip to content

fix(settlement): a pull request closed during a run the user did not start does not settle the thread - #46

Merged
maschwenk merged 2 commits into
mainfrom
fix/self-closed-pr-settle
Nov 9, 2026
Merged

maschwenk merged 2 commits into
mainfrom
fix/self-closed-pr-settle

Conversation

@maschwenk

@maschwenk maschwenk commented Nov 9, 2026 •

Copy link
Copy Markdown
Owner

the git checkout speed thread got auto-settled right as a background wake ended with "want both, or just one?". the only thing that tripped it was the agent closing its own throwaway diagnostic PR during that wake. a closed PR settles no matter what autoSettleOnMerge says, so the settle landed the second the run went idle

what changed

  • a linked PR that got closed during a run i didn't start is now treated as work the thread did. "didn't start" means the run's prompt wasn't a message i wrote: a scheduled task, a background command notice, a subagent finishing, or another agent's message. the link gets dropped (same as the existing rule for links added after they already finished), and the decision falls through to the other links, then the inactivity timer
  • a close during a run that my own message started still settles. that's the "you can close it" / "close the PR. no need to do anything else" flow
  • closing a PR between runs (me closing an abandoned one by hand) still settles
  • merges aren't touched
  • only applies to persisted links. the branch lookup path for unlinked threads isn't touched

why it's keyed on what started the run

first version blocked every close that happened during any run. an audit of last week's close settles found all 4 happened during the thread's own run, and 3 of them were right to settle: 2 where my message started the run and asked for the close, 1 where a run my message started closed a superseded PR and wrapped up. the only bad one was the incident, where a background command notice started the run. the github close actor is no help here since agent gh calls run as me

user-authored means the run's prompt message has createdBy = 'user' and no scheduledTaskId. scheduled task prompts carry whoever created the task, so one i scheduled still counts as automated. if the prompt message is missing the run counts as mine, so the old behavior holds

run history

the candidate only had latest run timestamps. that covers the exact incident but not the next wake: if another background run happens before i write again, the close isn't in the latest run anymore, it's still newer than my last message, and the thread settles when that wake ends. same bug one wake later

so the candidate now carries the windows of automated runs, but only for threads with a closed link newer than my last message. that's rare, so most sweeps skip the extra query entirely. when it does run it's one batched query for those threads, bounded to runs that ended at or after the earliest close, using the (thread_id, ordinal) index plus a primary key lookup of each run's prompt message. idle compaction runs and runs that never started are left out

known tradeoffs

  • if i close a PR by hand while an automated run is going, it doesn't count either. no way to tell those apart, and the inactivity timer still catches it
  • restart and usage limit continuations are prompted by the server, so a close in a continuation of a run i started counts as automated. same if i steer a message into a run a notice started. both fall back to inactivity
  • no clock skew grace. closedAt is github's clock and run times are ours, so a close in the last second of a run could land just outside the window. in practice the agent's final message comes several seconds after the close

written with claude opus 5.5 in claude code

…does not settle it

A background wake closed its own throwaway diagnostic pull request, and the
thread auto-settled the moment that run ended, right after the agent asked
the user a question. Treat a link closed while one of the thread's runs was
working as work the thread did, like links added after they finished, so the
decision falls through to the other links and the inactivity timer.

Settlement candidates now carry the windows of runs that could contain such a
close, read only for threads with a link closed since the user last wrote.
@maschwenk maschwenk added the coder-task-generated Created from a coding task label Nov 9, 2026
@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M labels Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ The exact PR base did not have a successful artifact. Baseline uses the latest successful main measurement shown below.
⚠️ This PR changes transfer ceilings:

  • Codex Live turn WebSocket decoded: 29.3 KiB → 24.4 KiB
  • Claude Live turn WebSocket decoded: 29.3 KiB → 24.4 KiB
Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.0 KiB 5.0 KiB +33 B (+0.6%) 6.8 KiB ✅
Codex Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.2 KiB 1.2 KiB +33 B (+2.7%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 20.9 KiB 21.5 KiB +674 B (+3.2%) 24.4 KiB ✅
Codex Live turn messages 2 1 −1 (−50.0%) 8 ✅
Claude Total thread wire 5.0 KiB 5.0 KiB +32 B (+0.6%) 6.8 KiB ✅
Claude Thread snapshot wire 3.8 KiB 3.8 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.2 KiB 1.2 KiB +32 B (+2.6%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 21.2 KiB 21.9 KiB +686 B (+3.2%) 24.4 KiB ✅
Claude Live turn messages 2 1 −1 (−50.0%) 8 ✅

Baseline: cdc3e41 · PR result: aba879e · Source CI: failure

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

…settling

An audit of last week's close settles showed all four happened during the
thread's own run, and three were correct: the user's message started the run
and asked for the close, or the run wrapped up a superseded PR. Only the
incident's close came from a run a background notice started.

Key the rule on what started the run. A close during a run whose prompt the
user did not write (a scheduled task, a notice, a subagent completion, or
another agent's message) is the thread's own work and cannot settle it. A
close during a run the user's message started settles as before.
@maschwenk maschwenk changed the title fix(settlement): a pull request the thread closed during its own run does not settle it fix(settlement): a pull request closed during a run the user did not start does not settle the thread Nov 9, 2026
@github-actions github-actions Bot added size:L and removed size:M labels Nov 9, 2026
@maschwenk
maschwenk marked this pull request as ready for review November 9, 2026 10:11
@maschwenk
maschwenk merged commit 9278569 into main Nov 9, 2026
27 of 29 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coder-task-generated Created from a coding task size:L vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant