Skip to content

fix(chat): an approved command runs once, and a step that did not run is never reported as executed (#21959) - #21964

Merged
mrveiss merged 7 commits into
mainfrom
issue-21959
Nov 21, 2026
Merged

mrveiss merged 7 commits into
mainfrom
issue-21959

Conversation

@mrveiss

@mrveiss mrveiss commented Nov 21, 2026 •

Copy link
Copy Markdown
Owner

Refs #21959, Refs #21751, Refs #13250

Thinking Path

After the graph's approval resume, execute_tools re-dispatched execute_command. The dispatch seam already recognises the approved call through the fingerprint set (ctx.approved_fingerprints, #18430) and returns RUN, but the terminal service then resolves the line again from the role policy (resolve_command_line in services/agent_terminal/ai_line_gate.py). A MEDIUM command is held there, queued as pending_approval, persisted as a second approval card, and polled and never answered. The recorded step (status pending_approval or outcome_unknown) was then counted as an executed step, so the model reported a success that never happened.

Fix: the seam marks an execute_command call whose exact fingerprint the person approved (COMMAND_APPROVED_KEY, reusing the existing fingerprint binding, no new mechanism). The mark travels to decide_command, which treats it as line 2 satisfied. Line 3 (refuse), the risk assessment and the agent permission check still apply. A model-supplied mark is dropped at the seam, and a yes for command X never matches command Y, because the fingerprint covers the raw params.

The approval is consumed by the call it marks, so a duplicate or retried call of the same fingerprint is held again.

Design: a human yes on the exact command satisfies a "needs a human yes" hold in the terminal, including the role-based hold on a HIGH-risk command. The approver is the chat owner the resume route already checked. REFUSE (line 3), the risk assessment and the agent permission check still block.

The continuation prompt counts and describes only steps known to have run (chat_workflow/step_outcome.py). did_execute fails closed: only success, executed (compose) and completed (delegate), or an error carrying a real exit code or output, count. A permission-denied record or an unknown status is NOT RUN.

#13250 (the double gate) is not unified here; only what these two issues need.

What Changed

  • chat_workflow/tool_dispatch_guards.py: COMMAND_APPROVED_KEY, _carry_person_approval, forged-key drop.
  • chat_workflow/tool_handler.py, tools/terminal_tool.py, services/agent_terminal/service.py, services/agent_terminal/ai_line_gate.py: person_approved carried through to decide_command.
  • chat_workflow/step_outcome.py (new) and chat_workflow/manager.py: executed-steps count and a "NOT RUN" line for pending, denied, refused or timed-out steps.
  • tests/unit/chat_workflow/test_approved_command_runs_once_21959.py (new).
  • Grandfathered files do not grow: tool_handler 3572 to 3571, manager 3728 to 3727. Three small formatting-only hunks in tool_handler.py (two logger calls, one metadata dict) and one in manager.py (_log_task_complete) are the minimum needed to stay at or under the file-size ceiling; check_python_file_size.py exits 0.

The second card stored and streamed on resume (#21751's live recurrence) came from the second terminal gate; with that gate no longer firing for an approved call, there is one card.

Verification

  • pytest autobot-backend/tests/unit/chat_workflow/test_approved_command_runs_once_21959.py: 17 passed. They cover approve then resume running once with no second gate, an unapproved command still held, a yes for one command not covering another, a forged flag dropped, a refusal not lifted, and a pending step reported as not run and not counted.
  • Related chat_workflow suites (-k approval or hold or continuation or held or execution_result or command): 239 passed.
  • ruff check and black --check clean on touched files.

Code ACs met: #21959 AC1 and AC2; #21751's card-count AC (test pinned in #21749, live recurrence root-caused here).

Not yet verified (ticked only after deploy)

Model Used

Claude Sonnet 5.5

Summary by CodeRabbit

  • New Features
    • Previously approved terminal commands can now proceed when the exact command is resumed, with approval applying only once.
    • Workflow summaries now distinguish steps that ran from those that did not, including pending, refused, timed-out and denied steps.
  • Bug Fixes
    • Continuation prompts now count steps that actually ran rather than all recorded steps, and failed commands are still counted as run when execution results are present.
    • Approval markers are cleared before evaluating a command, preventing an incoming marker from granting approval.

@mrveiss mrveiss added the phase:M2.4 Tasks and company workflows label Nov 21, 2026
@coderabbitai

coderabbitai Bot commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 56 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 543228f and 81c1b18.

Files selected for processing: 8

  • autobot-backend/chat_workflow/manager.py
  • autobot-backend/chat_workflow/step_outcome.py
  • autobot-backend/chat_workflow/tool_dispatch_guards.py
  • autobot-backend/chat_workflow/tool_handler.py
  • autobot-backend/services/agent_terminal/ai_line_gate.py
  • autobot-backend/services/agent_terminal/service.py
  • autobot-backend/tests/unit/chat_workflow/test_approved_command_runs_once_21959.py
  • autobot-backend/tools/terminal_tool.py
Walkthrough

The change adds one-time approval propagation for matching terminal commands and updates workflow history reporting. Continuation prompts count executed steps, and formatted history marks steps that did not run.

Changes: Command approval

Layer / File(s) Summary
Mark and forward command approvals
autobot-backend/chat_workflow/tool_dispatch_guards.py, autobot-backend/chat_workflow/tool_handler.py, autobot-backend/tools/terminal_tool.py
A matching approval fingerprint marks an execute_command call, and the fingerprint is consumed. The person_approved value passes through the tool handler and terminal tool. Two log changes only reformat existing messages and metadata.
Apply approval at the command gate
autobot-backend/services/agent_terminal/ai_line_gate.py, autobot-backend/services/agent_terminal/service.py, autobot-backend/tests/unit/chat_workflow/test_approved_command_runs_once_21959.py
The command decision gate accepts person_approved and allows a marked command unless approval is forced. Tests cover matching fingerprints, one-time use, forged markers, refusals, permission checks, and terminal dispatches.

Workflow step history

Layer / File(s) Summary
Classify and report workflow steps
autobot-backend/chat_workflow/step_outcome.py, autobot-backend/chat_workflow/manager.py, autobot-backend/tests/unit/chat_workflow/test_approved_command_runs_once_21959.py
New helpers classify executed steps, count them, and return a NOT RUN note for other steps. The manager uses these results in formatted history and continuation prompts. Tests cover status classification and prompt counts.
Merge Risk: Moderate · previous review 54322

When a command is refused, the continuation prompt can still report it as executed. The assistant may then describe the step as done after the command never ran. The approval changes themselves look sound. Fix the refusal case so refused steps stay marked NOT RUN before merging.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names two changes: an approved command runs once, and a step that did not run is never reported as executed. Both match the objectives and the file summaries. The approval marker (person_app…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names two changes: an approved command runs once, and a step that did not run is never reported as executed. Both match the objectives and the file summaries. The approval marker (person_approved) is carried through the tool dispatch, terminal service and ai_line_gate, and the continuation prompt counts only executed steps via did_execute, executed_count and not_run_note. The title is specific and concise. It uses the fix(chat) prefix and the issue number, which fits the convention for this repository.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@github-actions

Copy link
Copy Markdown
Contributor

Notice: 29 open PRs — past the runaway threshold (25)

This is not a request to defer this PR. There is no cap on open PRs (#19397) -- nothing blocks opening or pushing a PR.

This notice only means the count is high enough to be worth a glance for a runaway — something opening PRs in a loop, or a merge pipeline that has stalled so nothing is draining.

Currently open:

If the queue is draining normally, ignore this. Otherwise:

  1. Check whether CI is dispatching at all — see the ci-dispatch-watchdog status on these PRs
  2. Approved PRs land through the merge train the coordinator sequences (merge commits, never squash) -- check the open chore(merge-train) PR is moving, not each PR on its own
  3. Look for a loop opening near-identical PRs

Warn-only runaway detector — .github/workflows/pr-queue-gate.yml. It never blocks a merge.

@github-actions

Copy link
Copy Markdown
Contributor

✅ SSOT Configuration Compliance: Passing

🎉 No new hardcoded values of either class — ssot and other both block.

Known backlog in pipeline-scripts/hardcoded_values_baseline.txt is suppressed and tracked in #14371.

@mrveiss mrveiss removed the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 21, 2026
main shrank service.py to 860 lines; the person_approved plumbing grew it to 869.
The two decide_command flags now pass through as keyword flags, so the file stays at 860.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 23e7cd7 and 543228f.

Files selected for processing: 8

  • autobot-backend/chat_workflow/manager.py
  • autobot-backend/chat_workflow/step_outcome.py
  • autobot-backend/chat_workflow/tool_dispatch_guards.py
  • autobot-backend/chat_workflow/tool_handler.py
  • autobot-backend/services/agent_terminal/ai_line_gate.py
  • autobot-backend/services/agent_terminal/service.py
  • autobot-backend/tests/unit/chat_workflow/test_approved_command_runs_once_21959.py
  • autobot-backend/tools/terminal_tool.py

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

…NOT RUN (#21959)

_format_command_failure and _record_failed_step defaulted a missing return_code
to 1, so a refusal (no exit code, no output) counted as a run that failed. Both
now carry an exit code only when the result has one (key omitted, never None,
#14148).
@mrveiss mrveiss added the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 21, 2026
@mrveiss
mrveiss merged commit f349aa7 into main Nov 21, 2026
64 checks passed
@mrveiss
mrveiss deleted the issue-21959 branch November 21, 2026 20:24
@mrveiss mrveiss removed the land-next Landing set: CI capacity goes to these PRs first (owner direction 2026-09-18, #15397) label Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

phase:M2.4 Tasks and company workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant