Skip to content

feat: add Worker Efficiency Protocol to headless worker dispatch#793

Merged
marcusquinn merged 1 commit intomainfrom
feat/worker-efficiency-protocol
Feb 9, 2026
Merged

feat: add Worker Efficiency Protocol to headless worker dispatch#793
marcusquinn merged 1 commit intomainfrom
feat/worker-efficiency-protocol

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Feb 9, 2026

Summary

  • Injects a Worker Efficiency Protocol into the supervisor dispatch prompt (build_dispatch_cmd) so all headless workers receive structured efficiency guidance
  • Documents the protocol in headless-dispatch.md with rationale and ROI analysis

What Changed

supervisor-helper.sh — Dispatch Prompt Enhancement

Added a new ## Worker Efficiency Protocol section to the prompt injected into every worker session. Workers are now instructed to:

  1. Decompose with TodoWrite (MANDATORY) — Break task into 3-7 subtasks at session start. Provides progress breadcrumb trail that survives context compaction.
  2. Checkpoint after each subtask — Call session-checkpoint-helper.sh save so progress persists to disk. Enables resume-from-checkpoint instead of restart-from-scratch.
  3. Parallel sub-work — Use Task tool for independent subtasks (e.g., tests + docs simultaneously). Only when subtasks don't modify the same files.
  4. Fail fast — Verify assumptions before writing code (read target files, check deps exist, confirm task isn't already done).
  5. Minimise token waste — Read file ranges not whole files, concise commits, exit with BLOCKED after one failed retry.

headless-dispatch.md — Documentation

New "Worker Efficiency Protocol" section documenting:

  • The five key practices
  • Before/after comparison table
  • Token cost analysis (~200 tokens overhead vs 10K-50K saved per avoided restart = 30-150x ROI)

Why

Workers currently operate linearly with no internal structure. When context compacts mid-task, they lose all progress and restart from scratch — burning 2x the tokens. Complex tasks with multiple phases (research, implement, test, PR) have no explicit tracking, so workers sometimes skip steps or repeat them.

The protocol adds ~200-300 tokens per session but prevents full restarts that cost 10,000-50,000 tokens each.

Testing

  • ShellCheck: no new violations (resolved SC2153 false positive by using <your-task-id> placeholder)
  • bash -n: syntax OK
  • markdownlint: clean
  • Prompt renders correctly within the existing build_dispatch_cmd function

Summary by CodeRabbit

  • Documentation
    • Updated internal guidance documentation for worker task management protocols, including structured task decomposition, session checkpointing, parallel processing strategies, and performance optimization techniques.

Inject structured efficiency guidance into supervisor-dispatched workers:
- MANDATORY TodoWrite decomposition (3-7 subtasks at session start)
- Checkpoint after each subtask for compaction resilience
- Parallel sub-work via Task tool for independent subtasks
- Fail-fast verification before writing code
- Token waste minimisation guidelines

Workers currently operate linearly with no internal structure. When context
compacts mid-task, they restart from scratch (2x token cost). This protocol
gives workers a progress breadcrumb trail that survives compaction, reducing
wasted retries by 30-150x ROI on the ~200 token overhead.

Also documents the protocol in headless-dispatch.md with rationale table.
@gemini-code-assist
Copy link

Summary of Changes

Hello @marcusquinn, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a "Worker Efficiency Protocol" designed to significantly improve the efficiency and cost-effectiveness of headless AI workers. By integrating structured guidance directly into the worker dispatch prompt and providing comprehensive documentation, the changes aim to prevent token waste from unnecessary restarts due to context compaction and ensure more systematic, checkpointed task execution. This initiative is projected to yield substantial token savings and lead to more reliable task completion.

Highlights

  • Worker Efficiency Protocol Injection: A new "Worker Efficiency Protocol" has been injected into the supervisor dispatch prompt for headless workers, providing structured guidance to maximize output per token.
  • Protocol Documentation: The newly introduced protocol is thoroughly documented in headless-dispatch.md, detailing its practices, rationale, and a return on investment (ROI) analysis regarding token savings.
Changelog
  • .agents/scripts/supervisor-helper.sh
    • Injected a new "Worker Efficiency Protocol" section into the worker prompt.
    • Outlined five key practices within the protocol: TodoWrite decomposition, subtask checkpointing, parallel sub-work, fail-fast verification, and token minimization.
  • .agents/tools/ai-assistants/headless-dispatch.md
    • Added a comprehensive "Worker Efficiency Protocol" section.
    • Detailed the five key practices of the protocol.
    • Included a "Why This Matters" comparison table illustrating benefits.
    • Provided a "Token Cost" analysis, demonstrating a significant ROI from avoided restarts.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 9, 2026

Caution

Review failed

The pull request is closed.

Walkthrough

Adds "Worker Efficiency Protocol" explanatory text to the BLOCKED-state message in supervisor-helper.sh and introduces the same protocol guidance to headless-dispatch.md documentation. Changes are purely content-focused with no functional logic modifications or API alterations.

Changes

Cohort / File(s) Summary
Supervisor Script Guidance
.agents/scripts/supervisor-helper.sh
Expands BLOCKED-state message with detailed "Worker Efficiency Protocol" section covering subtask decomposition, checkpointing, parallel work, fail-fast principles, and token-waste minimization.
Headless Dispatch Documentation
.agents/tools/ai-assistants/headless-dispatch.md
Introduces new "Worker Efficiency Protocol" section with cost/rationale table for structured task management; content appears duplicated consecutively within the file.

Estimated Code Review Effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly Related PRs

Poem

🤖 Workers march with protocol in hand,
Decomposed tasks and checkpoints planned,
Parallel whispers, fail-fast they stand,
Token-wise guardians, efficiency grand! ✨

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/worker-efficiency-protocol

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Feb 9, 2026

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 59 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Mon Feb 9 18:03:13 UTC 2026: Code review monitoring started
Mon Feb 9 18:03:14 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 59

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 59
  • VULNERABILITIES: 0

Generated on: Mon Feb 9 18:03:16 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 9, 2026

@marcusquinn marcusquinn merged commit 8b9072c into main Feb 9, 2026
9 of 10 checks passed
Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a 'Worker Efficiency Protocol' for headless workers. The changes are clear and well-documented. My main feedback remains a suggestion to improve maintainability by externalizing the large prompt text from supervisor-helper.sh into a separate file, aligning with existing repository patterns for managing prompts.

Comment on lines +3385 to +3421
## Worker Efficiency Protocol

Maximise your output per token. Follow these practices to avoid wasted work:

**1. Decompose with TodoWrite (MANDATORY)**
At the START of your session, use the TodoWrite tool to break your task into 3-7 subtasks.
Example for 'add retry logic to API client':
- Research: read existing API client code and error handling patterns
- Implement: add retry with exponential backoff to the HTTP client
- Test: write unit tests for retry behaviour (success, max retries, backoff timing)
- Integrate: update callers if the API surface changed
- Verify: run linters, shellcheck, and existing tests

Mark each subtask in_progress when you start it and completed when done.
Only have ONE subtask in_progress at a time.

**2. Checkpoint after each subtask**
After completing each subtask, run:
\`session-checkpoint-helper.sh save --task <your-task-id> --next 'remaining subtask descriptions'\`
This persists your progress to disk. If context compacts or the session restarts,
your checkpoint survives and you can resume from where you left off instead of restarting.

**3. Parallel sub-work with Task tool**
If your subtasks include independent work (e.g., writing tests while docs are separate),
use the Task tool to spawn a sub-agent for the independent piece. This is faster than
doing everything sequentially. Only parallelise when the subtasks don't modify the same files.

**4. Fail fast, not late**
Before writing any code, verify your assumptions:
- Read the files you plan to modify (stale assumptions waste entire sessions)
- Check that dependencies/imports you plan to use actually exist in the project
- If the task seems already done, EXIT immediately with explanation — don't redo work

**5. Minimise token waste**
- Don't read entire large files — use line ranges from search results
- Don't output verbose explanations in commit messages — be concise
- Don't retry failed approaches more than once — exit with BLOCKED instead"

Choose a reason for hiding this comment

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

medium

This large block of prompt text is being added directly into the script. For better maintainability and separation of concerns, consider moving this 'Worker Efficiency Protocol' into its own file within a prompts directory (e.g., .agents/prompts/worker_efficiency_protocol.md).

This would decouple the prompt content from the script logic, making it easier to manage and edit the protocol without modifying the shell script, which is already quite large. The script could then load this content dynamically.

This pattern of externalizing prompt content appears to be in use elsewhere in the repository (e.g., prompts/build.txt).

@marcusquinn marcusquinn deleted the feat/worker-efficiency-protocol branch February 21, 2026 01:59
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