Skip to content

BDSP AutoStory: breakpoints pause before each step and each leg - #452

Draft
dayfine wants to merge 224 commits into
bdsp/autostory-v4from
bdsp/story-breakpoints
Draft

dayfine wants to merge 224 commits into
bdsp/autostory-v4from
bdsp/story-breakpoints

Conversation

@dayfine

@dayfine dayfine commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Depends on #448

BDSP AutoStory could not stop at breakpoints. The panel now hands the BREAKPOINTS option's pause points to the executor (a pause before each step) and to the planned-route walker and the fixed-leg steps (a pause before each leg, labelled like "12.03/5 pallet_shore leg 2/5 east 4 -> (10,10)"). RouteIO gets a free leg_started that logs the leg line and then pauses.

Tested with the headless runner: the "a leg's breakpoint" planned-route case and the existing planned-route, StoryStepExecutor and StoryEngine suites pass. Not run on the console.

🤖 Generated with Claude Code

https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss

dayfine and others added 30 commits October 29, 2026 13:56
Games open the Switch's own keyboard for names (e.g. BDSP's player name).
keyboard_enter_code() types on it blind from an assumed starting key, so it
can't recover from a press the keyboard ignored while sliding in, or start
from wherever the keyboard left its cursor.

SystemKeyboardDetector recognizes the keyboard (OK blue, or grey while the
field is empty), find_system_keyboard_cursor() reads the key under the cursor,
and system_keyboard_field_has_text() says whether the field is empty. Unit
tests cover all three on six reference screenshots (CommandLineTests,
NintendoSwitch/SystemKeyboardDetector).

type_on_system_keyboard() in FastCodeEntry reads the cursor before each key
and moves it with keyboard_get_path(), now declared in the header, over
KEYBOARD_POSITIONS, so it shares the key grid and the wrap-around moves with
blind code entry and also supports AZERTY.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Move the game-agnostic part of SV's checkpoint_reattempt_loop and
checkpoint_save into Pokemon/AutoStory/Pokemon_CheckpointRetry: the retry
policy, reset counter and StoryLog lines, with the game's run, report,
reset and give-up as callables. SV keeps its saves and messages and its
historical counts (102 attempts, report on the 11th failure).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
The tutorial and main story checkpoint dropdowns are now the shared
StoryRangeOptions, added under the same keys (START_CHECKPOINT_TUTORIAL,
END_CHECKPOINT_TUTORIAL, START_CHECKPOINT_MAINSTORY, END_CHECKPOINT_MAINSTORY)
over the same databases, so saved settings load unchanged; the end stays
unlocked while running. The start-before-end check is the range's. The
checkpoint loops log the shared attempt and reset lines, and the run logs
the shared checkpoint start line.

Rebased onto autostory/story-range-options (#325) and squashed: it
uses only the shared range options (#325) and log lines (#45), not #312.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
…tory-options

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Shared plumbing for seam 3's sim goldens: a golden's path beside its
test, its text, the first differing line, and a check that rewrites the
file when PA_UPDATE_SIM_GOLDENS is set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
… for the sims

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
…tory-options

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
dayfine and others added 30 commits November 13, 2026 21:50
The checkpoint lines take `bool add_checkpoint_prefix = true` in place of
`display_text`. SV passes its checkpoint text as `checkpoint` with the prefix
off, so NO_CHECKPOINT_ID goes. Literal positional arguments carry a
parameter-name comment. SV's reset lines now pass the attempt limit slot
explicitly (they passed the text into it before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
…dd_checkpoint_prefix (#45)

Conflict in PokemonSV_AutoStoryTools.cpp reset lines: took #45's add_checkpoint_prefix form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
…_checkpoint_prefix (#45)

Conflicts in PokemonSV_AutoStoryTools.cpp: kept this PR's retry-loop
rewrite. CheckpointAttempts::display_text becomes add_checkpoint_prefix,
and CheckpointRetry passes its checkpoint text with the prefix off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
…1879)

* HttpServer: add a minimal Qt-free HTTP/1.1 server on AbstractServerSocket

A minimal HTTP/1.1 server for a single local client that issues one
request at a time (e.g. an MCP client), built on the socket library
instead of Qt:

- One connection at a time (the server socket's model); requests are
  processed in order, so pipelined bytes simply wait in the buffer.
- The per-connection task does all parsing and writing; the socket's
  receive callbacks only append data and flip flags. The user handler
  may block on another thread (e.g. the program thread) and can poll
  HandlerContext::connection_alive() to bail out of long-running work;
  responses are discarded if the connection dies meanwhile.
- Content-Length bodies only (chunked -> 411), sizes capped
  (8 KB request line, 64 KB headers, 1 MiB body, 2 MiB buffer),
  "Expect: 100-continue" answered, strict request/header validation
  (400), responses always carry Content-Length.
- start()/stop() are fully synchronous from the caller's point of view
  once on_listen_finished has fired: stop() closes the connection,
  waits for the in-flight handler, and joins the socket's worker
  threads, so the server can be started again afterwards.

No TLS, no upgrades, no method routing or auth: the user handler owns
all of that. 10 loopback tests (raw ClientSocket clients) cover the
happy path, keep-alive, pipelining, Connection: close, 400/411/413,
100-continue, disconnect and stop() during a handler, and
second-client rejection.

Part of the groundwork for the in-app MCP server; stacks on the
ServerSocket factory alias PR.

* HttpServer: fix CI build failures

- Rename ParseState::ERROR to ParseState::ERROR_RESPONSE: ERROR is a
  macro on Windows (winerror.h), which broke the qualified name on
  MSVC and clang-cl (C2589).
- Keep the AsyncTask handle from ThreadPool::dispatch in the
  stop-during-handler test: dispatch is [[nodiscard]] and clang's
  -Wunused-result (CI's -Werror) rejects discarding it. Its destructor
  also waits for the trivial release task to finish.

* HttpServer: inherit from AbstractHttpServer; address review

Split the request/response types, the handler contract, and the
listener events out into AbstractHttpServer (stacked on the
extract-abstract-http-server PR); HttpServer now implements that
interface, with the types re-exported under its own name.

Fixes from the review:

- Deadlock in on_connect(): the connection task handle was moved into
  m_connection_task while holding m_lock, and destroying the old handle
  blocked on the old task, whose final cleanup takes m_lock. Task
  handles now live in m_tasks under a dedicated m_task_lock (the socket
  library's m_task_lock pattern): on_connect() dispatches outside
  m_lock and never waits on an old task, so a new client is no longer
  held up while the previous handler is still running.
- Deadlock in stop(): the socket was destroyed while holding m_lock,
  and ~ServerSocket joins the socket's worker threads, whose callbacks
  take m_lock. The socket is now moved out under m_lock and destroyed
  after releasing it.
- Busy-spin on partial requests: the wait predicate was
  !buffer.empty(), which is permanently true once a partial request is
  buffered. It now requires the buffer to have grown past what the
  parse just saw, plus the dead/stop flags.
- Chunked requests: 501 Not Implemented instead of 411 (RFC 9112).
- The 413 check at parse time was unreachable (an incomplete request
  is always smaller than the buffer cap); the 2 MiB buffer cap is now
  enforced when data is appended instead, closing the connection.
- end_connection() only closes the socket's connection while it still
  belongs to this connection, so a task noticing its own connection
  died late cannot close the next client's connection.
- Documented that start()/stop() are not thread-safe with each other.

Test: new case that a connection flooding past the buffer cap is
closed without a response while the server keeps listening; chunked
case now expects 501.

* HttpServer: close the reconnect write race from the review

The socket's connection thread sets the state back to LISTENING before
it reports the disconnect, so a fast reconnect can be accepted before
the old connection's on_disconnect callback runs. Two consequences:

- The old connection's task could then write its final response through
  socket->send() into the new client's socket (send() has no
  per-connection identity; it writes whatever the socket is connected
  to). on_connect() now marks the connection it replaces dead (and
  notifies it) before the new one takes over, so the old task's
  post-handler check discards its response.
- on_disconnect() marked m_connection dead, which in that window is the
  new client's connection: it would kill the new connection task. It
  now only does so while the socket is not already CONNECTED to the
  next client.

Test: a client disconnects while its handler is still blocked on a
gate; a second client connects (replacing the first in the server)
before the gate is released. The first handler's late response must be
discarded, and the second client's stream must contain only its own
response.

* HttpServer: address the second review round

Five items from the fresh review:

- [P1] stop() could hang waiting for a handler: the socket suppresses
  its disconnect callback for a close_connection() close, so a handler
  polling connection_alive() kept seeing true while shutdown waited
  for it. stop() now marks the active connection dead before it waits.
  The stop-during-handler test now polls connection_alive() after the
  gate, which would spin forever without the mark.
- [P1] A response could reach a different client after reconnection:
  every write now carries the connection's socket id
  (AbstractServerSocket::connection_id(), new), so the socket refuses
  a write whose connection was replaced. This closes the last of the
  'task outlives the connection' windows; the id check and the
  transport selection happen under the socket's lock.
- [P2] Expect: 100-continue stalled clients: the interim response was
  sent only after the complete request (including body) was parsed,
  which a client waiting for it before sending the body never sees.
  Parsing now reports a separate NEED_BODY state (headers complete and
  valid, body pending), and the 100 is answered at that point. The
  test now performs the real two-phase handshake.
- [P2] Complete headers bypassed the 64 KiB limit: the in-progress
  check only fires while the terminator is still missing. The
  completed header boundary is now checked against the limit too, with
  a test sending a ~75 KiB header section in one piece.
- [P2] The test client's receive buffer was a data race: 'received'
  and the error strings are now protected by the waiter's mutex, and
  assertions use synchronized snapshots (same for the server
  listener's listen error).

* Cleanup

---------

Co-authored-by: PA Dev Bot <344001113+pa-devbot@users.noreply.github.com>
Co-authored-by: Alexander Yee <a-yee@u.northwestern.edu>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
The SystemKeyboardDetector screenshots are on the fork's CommandLineTests
main, not upstream's, so the image tests could not load them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
# Conflicts:
#	SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
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.

4 participants