bug: hire-an-agent TOML editor corrupts existing [agents.X] block on re-run #886
Labels
No labels
action
backlog
blocked
bug-report
cannot-reproduce
in-progress
in-triage
needs-triage
prediction/actioned
prediction/dismissed
prediction/unreviewed
priority
rejected
reproduced
tech-debt
underspecified
vision
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: disinto-admin/disinto#886
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Re-running
disinto hire-an-agent <name>for an agent that already has a[agents.<name>]section inprojects/<project>.tomlcorrupts the TOML file. The Python regex-based editor inlib/hire-agent.sh(invoked in Step 6 —Writing [agents.X] to ...) does not handle the case where the existing block is present in commented-out form or when it re-encounters its own prior output.Repro
Starting state:
projects/disinto.tomlcontains a clean[agents.dev-qwen2]block.After the re-run,
projects/disinto.tomlcontains the following mess (observed today):# [agents.dev-qwen2]header stayed commented out (workaround from #862 era).base_url = ...line throughpoll_interval = 60are NOT in any section — they attach to[monitoring](the preceding table).["dev"]is a malformed TOML fragment (looks like the regex grabbedroles = ["dev"]and emitted the rest of that line as a standalone header).Result:
tomllib.load()fails → both early-parse and late-parse paths inentrypoint.shsilently skip →PROJECT_NAMEstays at the compose default → clone lands in wrong directory (see also #861).Root cause
lib/hire-agent.shwrites the TOML section using a Pythonre.subblock (search shows regex patterns near line ~445–475). The regex:# [agents.X]) as "already present," so it creates a second incarnation while leaving the commented block in place.[monitoring]section instead of in a dedicated location, with no trailing newline/section anchor — subsequent keys attach to whatever section currently precedes them.["dev"]artifact suggests the regex matched onroles = ["dev"]and substituted only part of the line.Fix
Use a proper TOML library (
tomllibin read-only form already available;tomli_wor manual re-serialization for write) instead of regex. The editor should:tomllib.agents.<name>sub-table in the parsed structure.This is robust to comments, section reordering, and repeated runs.
Acceptance
disinto hire-an-agent <name>for an existing agent produces a clean, idempotent TOML (no duplicate blocks, no orphan keys, no invalid["dev"]artifacts)tomllib.load()succeeds on the resulting file[agents.<name>]blocks are either cleaned up or left untouched — but NEVER produce mixed stateAffected files
lib/hire-agent.sh— Step 6 TOML writer (Python heredoc around line 440–475)Context
Caught during today's dev-qwen2 re-hire after #862 landed. Had to manually patch
projects/disinto.tomlwith a separate Python script to unblock. The re-hire scenario is not a hypothetical — idempotent re-runs are explicitly required by #800.