Skip to content

fix: give the spec-mode examples a realistic task - #85

Open
factory-droid[bot] wants to merge 3 commits into
mainfrom
droid/spec-newline-prompt
Open

factory-droid[bot] wants to merge 3 commits into
mainfrom
droid/spec-newline-prompt

Conversation

@factory-droid

@factory-droid factory-droid Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Description

What: The three spec-mode examples (enter-spec-mode, spec-mode-same-session, spec-mode-new-session) now ask Droid for a short Markdown note (hello.md, a note that says hello, or one titled "Hello from Droid") instead of a file containing "hello". The permission handlers are unchanged. In the harness, the enter-spec-mode check now looks for "hello" in the note the example prints, instead of requiring the last stdout line to be exactly hello. enter-spec-mode prints the note under a hello.md: line so the check can tell it apart from the plan, which is printed earlier.

Why: The scheduled Examples workflow keeps failing on enter-spec-mode, and spec-mode-same-session sometimes needs retries. The failing runs end with Turn ended: interrupted.

Root cause: containing "hello" reads as exact file contents, and the prompt also rules out shell commands. File tools always end a file with a newline. So after writing a correct file, Droid keeps trying to remove that newline: it re-patches the file, runs read-only checks such as which vim, tries vi or npm exec, or asks (AskUser) "How should I handle the trailing newline in hello.txt?". The handler cancels those commands, and the SDK cancels AskUser because the examples set no askUserHandler. A cancel ends the turn, so the example exits 1 even though the file is already on disk.

A short note is a task where exact bytes don't matter. That is closer to how a user would use spec mode, and it removes the conflict without changing the handlers.

Supersedes #84. #84 lets enter-spec-mode approve low-impact shell commands. I tried that locally on droid 1.23.0, with an AskUser handler added as well: enter-spec-mode still failed 3 of 12 runs, because Droid moved on to medium-impact commands (vi, npm exec) to strip the newline.

Validation

  • npm test (14/14), npm run typecheck, npm run lint, npm run format:check, npm run check:docs: all pass.
  • node scripts/run-examples.mjs --only enter-spec-mode,spec-mode-same-session,spec-mode-new-session --runs 8 --retries 0, droid 1.23.0, Linux: 8/8 for each example, about 50k credits per run.
  • Separate local runs with every permission request logged (droid 1.23.0, same handlers):
Prompt enter-spec-mode spec-mode-same-session Cancelled tool calls or questions
main (containing "hello") 6/8 6/8 4
This PR (Markdown note) 12/12 12/12 0

The spec-mode examples asked for a file "containing \"hello\"". Droid
often read that as exact bytes with no trailing newline, which the file
tools cannot write. It then asked the user (AskUser) or checked the
bytes with a shell command. The examples cancel both, which ends the
turn as interrupted and fails the nightly Examples run.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@factory-droid

factory-droid Bot commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

The Nov 26 nightly on main failed the same way (droid 1.21.1): enter-spec-mode ended "interrupted" on both attempts on ubuntu/Node 22.23.5, and spec-mode-same-session needed a retry on macOS (https://github.com/Factory-AI/droid-sdk-typescript/actions/runs/45768917134).

I reran this branch on droid 1.21.1 with runs=2, retries=0: https://github.com/Factory-AI/droid-sdk-typescript/actions/runs/45772560049. Every job passed, and all three spec-mode examples passed 2/2 on every Node job with no retries.

@factory-davidgu factory-davidgu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This seems like an example change to please the tests, but the change in the example is not really useful for users. I think we should probably fix the test, and possibly make the examples more specific, but not like this

Ask for a short Markdown note instead of a file "containing" an exact
string. The exact-string wording made Droid try to strip the newline that
file tools add, through shell commands or AskUser, which the examples
cancel, ending the turn. Drop the earlier trailing-newline prompt text.
The enter-spec-mode check now looks for hello in the printed note.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@factory-droid factory-droid Bot changed the title fix: tell spec-mode examples a trailing newline is fine fix: give the spec-mode examples a realistic task Nov 28, 2026
@factory-droid

factory-droid Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Agreed, thanks. The trailing-newline sentence was there only to keep the model on track, and it isn't useful to readers. I removed it, and the comments that explained it.

I logged every permission request to see what actually fails. containing "hello" reads as exact file contents, and the prompt also rules out shell commands. File tools always add a final newline, so after writing a correct file, Droid keeps trying to remove it: it runs which vim, tries vi or npm exec, or asks the user. The example cancels those, which ends the turn. I also tried fixing it in the handler instead, by approving low-impact commands and answering AskUser. enter-spec-mode still failed 3 of 12 runs, because Droid moved on to medium-impact commands.

So, following your suggestion, I made the examples more specific in a way that matches real use: each one now asks for a short Markdown note (hello.md, one that says hello or one titled "Hello from Droid"). The handlers are unchanged. On the test side, the enter-spec-mode check no longer requires the last line to be exactly hello. It now looks for hello in the note, which the example prints under a hello.md: line, after the plan.

Results (droid 1.23.0, no retries): harness 8/8 for each of the three examples. Separate logged runs: 12/12 for enter-spec-mode and 12/12 for spec-mode-same-session, with no cancelled tool calls, against 6/8 for each on main. Examples workflow on this branch (runs=2, retries=0): all jobs green, https://github.com/Factory-AI/droid-sdk-typescript/actions/runs/46186181964. The PR description has the details.

This branch has not been deployed

No deployments
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