Skip to content

Source Control: refresh the thread's PR right after an agent runs gh pr create / glab mr create #221

Closed

Description

@mubeda

Summary

When an agent opens a pull request itself, by running gh pr create or glab mr create through its shell tool, BiBCode doesn't notice. The thread's branch/PR status only picks up the new PR on the next passive summary cycle (30-second deadline) or the next lookup after the open-PR cache expires. Terminal commands and BiBCode's own Create PR already trigger an immediate refresh, but provider tool commands don't.

Trigger the existing local-change refresh as soon as a provider command_execution item settles with a PR/MR create command, so the PR shows up right after the agent prints its URL.

Current behavior (verified at a0ea849ef92b)

The refresh already exists

  • observe_local_changes (apps/server/src/production/git_vcs.rs:171-199) handles a reported local change for a worktree. It calls invalidate_open_pull_request_lookups(cwd) and spawns summary.notify_local_change, skipping the "30-second deadline". Its doc comment names this case: "a command such as gh pr create can change the hosting service's answer".
  • Open-PR lookups are cached for OPEN_PULL_REQUEST_LOOKUP_TTL = 10 s (apps/server/src/source_control/open_pull_request_lookups.rs:43, capacity 64 at :45).

Who triggers it today

  • Integrated terminal process exit: apps/server/src/production/runtime.rs:527-534 (set_process_exit_callback → status_broadcaster.notify_local_change).
  • Uploads: runtime.rs:210-222.
  • BiBCode's own PR create: it invalidates lookups at apps/server/src/source_control/pull_request.rs:700-711, and .with_created_request_observer(...) is wired at runtime.rs:520 (builder at git_vcs.rs:464).
  • rg notify_local_change finds callers only in git/summary.rs, git/broadcaster.rs:863, runtime.rs:219/533 and git_vcs.rs:192/198. No provider-runtime caller.

Provider commands are not observed

  • Provider events are projected in project_provider_event (apps/server/src/production/provider_runtime.rs:11054). It handles item.completed, e.g. compaction at :11171-11179, and turn.completed (:11180+), but has no VCS/PR hook.
  • command_execution is a tool lifecycle item type (packages/contracts/src/providerRuntime.ts:123-124).
  • Where the command text is:
    • Codex: command in params (apps/server/src/provider/codex/runtime.rs:2953; see the command_item_event_payload test, around :4623);
    • Claude Bash: input.command (apps/server/src/provider/claude/runtime.rs, test around :7087);
    • Cursor, OpenCode and Grok payload shapes not verified.
  • AI Terminal threads (provider CLI inside a PTY) only notify when the terminal process exits, not after each command.

I haven't measured the actual delay before the PR appears after an agent-run gh pr create. It depends on the summary cycle and the 10 s lookup TTL.

Proposed change

  1. Detector (pure function, unit-tested). For a settled item.completed with itemType: "command_execution", decide whether the command creates a PR/MR: gh pr create or glab mr create at command position. Handle:

    • shell wrappers (bash -lc, zsh -lc '…'), &&/;/| chains, quotes and heredocs;
    • false positives: echo "gh pr create" and grep 'gh pr create' must not match.

    Only the boolean result leaves the detector; command text is never logged.

  2. Observer. Add a narrow observer dependency to the provider runtime, like with_created_request_observer. When the detector matches, the runtime calls status_broadcaster.notify_local_change(<thread cwd/worktree>). That reuses observe_local_changes: invalidate lookups plus a fresh summary cycle. Optionally, also fire on any settled command whose output contains a PR/MR URL for the thread's remote.

  3. Debounce. At most one refresh per thread per settled item. A batch of commands in one turn produces one refresh.

T3 Code reference (their claims, not measured by us)

  • pingdotgg/t3code#24813, merged 2026-10-25 06:45 ART. A PullRequestSyncReactor links a thread to a PR from settled command_execution output.
  • Guards they describe:
    • Codex zsh -lc unwrapping;
    • heredocs and quotes;
    • command position only;
    • skipping when the output has more URLs than create commands.
  • They report 11 new tests and a replay of real threads that found 15 missed links and 0 wrong ones.
  • Known gaps they list: for loops and gh api calls.
  • T3 stores the thread↔PR link. BiBCode derives the PR from the branch (see Open questions).

Acceptance criteria

  • Rust unit tests for the detector (a new apps/server/src/source_control/pr_create_command.rs or similar, with colocated tests):
    • matches plain, bash -lc/zsh -lc-wrapped, chained and heredoc-body (--body-file -) forms of gh pr create and glab mr create;
    • rejects echo/grep/comment mentions and gh pr view/list;
    • rejects non-command-position matches.
  • Rust tests in apps/server/src/production/provider_runtime.rs (same module as the existing project_provider_event tests):
    • a settled Codex command_execution with gh pr create calls the observer once for the thread's cwd;
    • a Claude Bash item with the same command does the same;
    • an in-progress or failed-to-start item, or an unrelated command, doesn't call it.
  • apps/server/src/production/git_vcs.rs: a_reported_local_change_runs_a_fresh_lookup (:7297) still passes. A new case shows that a provider-reported change for a watched worktree runs a fresh open-PR lookup, without waiting for the TTL.
  • Desktop e2e: vp run test:ui:desktop, including apps/desktop/e2e/specs/chat-activity-panel.e2e.ts and project-session-terminal.e2e.ts (no regressions in command rows or terminal-exit refresh).
  • Manual: in a Codex thread and a Claude thread on a GitHub repo, ask the agent to push a branch and run gh pr create. The thread's PR status updates within a few seconds of the command finishing. Record the observed delay before and after the change.
  • Gates: cargo fmt --all --check, cargo clippy --workspace --all-targets -- -D warnings, relevant cargo test -p bibcode-server (provider_runtime, git_vcs, source_control), vp check (zero warnings), vp run typecheck, Release Smoke.
  • UI.md and vercel-react-best-practices reviews are recorded if any UI changes (none expected). docs/testing/ runbooks are reviewed and updated or stated "remain accurate".
  • Profiler coverage line in the delivery report. Command text and output (user and agent text) never reach profiler records or logs; only the match boolean and the cwd key do.

Living docs to update

  • docs/architecture/overview.md / docs/plans/pull-requests/research/server-provider-layer.md: list provider command completion as a local-change source next to terminal exit and uploads.

Not in scope

  • Persisting a thread↔PR link (see Open questions).
  • Parsing PR URLs from output to link PRs on other branches or repos.
  • for loops, scripts and gh api calls that create PRs (T3's known gaps).
  • AI Terminal per-command detection inside a PTY.

Related

  • The terminal-exit refresh (runtime.rs:527-534) and BiBCode's own create path (pull_request.rs:700-711) that this reuses.

Open questions

  • Should BiBCode store a durable thread↔PR link (as T3 does), so a thread keeps its PR after the branch is renamed, deleted or merged? Today the PR is found by branch lookup. That's a persisted shape and would need a docs/plans/ design doc.
  • Cursor, OpenCode and Grok command_execution payloads: where does the command text live? Not verified.
  • Should a settled command whose output contains a PR URL (but no recognized create command) also trigger the refresh?

Activity

  1. added
    enhancement
    on Oct 31, 2026
  2. mubeda commented on Oct 31, 2026

    @mubeda
    OwnerAuthor

    Triage, 2026-10-31. Not going into PR #213 (#139 MCP batch). It goes in a follow-up PR after that release. Batch 2 (quick fixes).

    PR #213 refreshes the Source Control panel only for PRs created through BiBCode's MCP create_pull_request tool, which goes through BiBCode's own create path. It does not handle an agent running gh pr create / glab mr create in its shell. production/provider_runtime.rs still never calls notify_local_change, so this issue is fully open.

    Planned order after the release: (1) #222 copy lint; (2) quick fixes #228, #221, #229, #231, #232; (3) MCP #220; (4) performance #225, then #223, #226, #227; (5) features #230, #224, #211, #212; (6) #210 after a Windows repro.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions