Skip to content

Fix Patrol finding: extend-the-internal-brainstorm-parser-with-a-sou-9d5375776123 - #1513

Closed
ivankuznetsov wants to merge 1 commit into
mainfrom
hive/patrol-fix/extend-the-internal-brainstorm-parser-with-a-sou-9d5375776123/g1
Closed

ivankuznetsov wants to merge 1 commit into
mainfrom
hive/patrol-fix/extend-the-internal-brainstorm-parser-with-a-sou-9d5375776123/g1

Conversation

@ivankuznetsov

@ivankuznetsov ivankuznetsov commented Oct 2, 2026 •

Copy link
Copy Markdown
Owner

Patrol Fix

This pull request repairs one finding tracked by Hive's Patrol Fix workflow.

Sources

  • architecture_patrol: scheduled-68a9c8e760715d08694bc0d42d93ebc1e35e48d77b46f863e2c86c27c7ecbab9:centralize-brainstorm-document-location

Finding evidence

  • {"file":"lib/hive/brainstorm_parser.rb","snippet":"Question = Struct.new(\n :round, :n, :text, :answer, :answer_encoding,\n keyword_init: true\n )","claim":"the canonical parser returns logical question data without source positions or block spans, so mutation callers cannot use its parse result to locate the corresponding document region"}
  • {"file":"lib/hive/bot/brainstorm_answer_writer.rb","snippet":"def target_question_line_index(lines, parsed, question_n)\n matching = parsed.select { |q| q.n == question_n }\n target_position = matching.find_index { |q| q.answer.nil? }","claim":"the writer reconstructs physical identity from raw lines after parsing because the parser boundary does not expose that decision"}
  • {"file":"lib/hive/bot/brainstorm_answer_writer.rb","snippet":"Previously this was a two-step scan: strict by-number first,\n # then by-position fallback. The strict scan ignored Q-context\n # and could cross round boundaries","claim":"the duplicated location rules have an observed behavioral consequence: an earlier implementation crossed round boundaries and routed a later-round answer into the wrong slot"}
  • {"file":"lib/hive/brainstorm_parser.rb","snippet":"The writer's find_empty_answer_slot has a\n # matching lenient fallback so the answer lands in the\n # actual slot on disk.","claim":"the current parser explicitly depends on a matching writer-side structural rule, making future format changes a synchronized cross-boundary edit"}

Independent review

The patch correctly centralizes question and answer locations in Hive::BrainstormParser and makes both writer paths consume the parser's normalized line-index space. No patch-related defect was found. The controller's only red validation is an unrelated AgentCliRuntime timeout test; that exact test passed independently, while every focused and adjacent parser/writer check remained green.

  • Reviewed the exact c2e6b77..07a5ee6 diff: only parser/writer logic, focused tests, and required wiki documentation changed; git diff --check was clean.
  • Parser Question values now expose question_line_index, answer_line_index, and exclusive block_end_index from document_lines; append and ordinal writes use those fields for fill or insertion, eliminating writer-side rescans while preserving Q, Round, marker, EOF, CRLF, and lone-CR behavior.
  • Independent focused verification passed: parser, writer, round-trip, and skill-contract tests reported 28 runs and 73 assertions; answer CLI and adjacent consumers reported 33 runs and 224 assertions; RuboCop inspected four changed Ruby and test files with no offenses.
  • The controller's architecture test failed only in components/agent-cli-runtime/test/probe_test.rb, outside this six-file patch; rerunning that exact timeout test passed with 1 run and 5 assertions.

Validation

Verdict: passed

  • Required CI: run 37165702708 passed on unchanged head 01aa23d389e0080e5b54365489e04dc67e9be9df.
  • architecture:test: exit 1 (unrelated AgentCliRuntime timeout; exact retry passed)
  • agent:parser-location-fields-and-answer-writer-round-trip: exit 0
  • agent:answer-cli-and-adjacent-consumers: exit 0
  • agent:style-gate-on-changed-files: exit 0

@ivankuznetsov
ivankuznetsov force-pushed the hive/patrol-fix/extend-the-internal-brainstorm-parser-with-a-sou-9d5375776123/g1 branch 3 times, most recently from 2c3de9d to 99cf198 Compare October 3, 2026 20:03
The shared brainstorm parser returned only logical question data
(round, number, text, answer), so BrainstormAnswerWriter had to
reconstruct physical identity from raw lines: target_question_line_index
re-scanned raw lines to map the parser's "first unanswered Q{n}" back to
a line index, question_line_index_for_ordinal re-scanned for the
ordinal-position Q header, and block_boundary? re-derived the
Q/Round/marker boundary rule the parser also encodes. Three parallel
location rules meant every future format change was a synchronized
cross-boundary edit, and the raw-line re-scan indexed a different line
array than the parser used (a lone-CR file yields more parser lines than
content.lines).

Centralize document location in Hive::BrainstormParser:

- Question now carries question_line_index, block_end_index (first
  Q/Round/marker boundary at-or-after the header, or EOF), and
  answer_line_index - all indexed against the parser's
  newline-normalized line array, now exposed as document_lines.
- The writer anchors directly on those fields: it selects the
  parser-identified unanswered target, fills the empty A-slot at
  answer_line_index before block_end_index, or inserts a new slot at
  block_end_index - no re-scan, no separate boundary rule.
- Writer line surgery runs on the parser's own line array (re-terminated
  with \n), so parser indices and raw lines can never disagree; the
  written document keeps the pre-write line-ending style (CRLF stays
  CRLF). The lone-CR write path now normalizes the whole document the
  same way the parser does.

The removed re-scan (target_question_line_index) was the last place a
writer-side positional guess could diverge from the parser, which is what
previously let a round boundary be crossed when routing an answer.
EOF-final questions (no trailing newline) keep their terminator, and
lone-CR documents now land answers instead of dead-ending in
:answer_slot_missing.
@ivankuznetsov
ivankuznetsov force-pushed the hive/patrol-fix/extend-the-internal-brainstorm-parser-with-a-sou-9d5375776123/g1 branch from 99cf198 to 01aa23d Compare October 4, 2026 00:41
@ivankuznetsov

Copy link
Copy Markdown
Owner Author

Merged as part of #1535, which batched the remaining ready PRs (including this PR's head) into one CI run.

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