Skip to content

feat: add Jev-powered Discord thread auto-renaming - #329

Merged
dnth merged 7 commits into
mainfrom
fm/fm-thread-autorename-v2
Nov 24, 2026
Merged

dnth merged 7 commits into
mainfrom
fm/fm-thread-autorename-v2

Conversation

@dnth

@dnth dnth commented Nov 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

One reconciler per Discord topic thread is now the only code that writes its title (issue 324 rebuild).
Each pass works out the title from saved state alone, then compares and writes:

reconcile(thread)                      # on a post, verdict, decision open/close, wait ending, or the 10-min safety sweep
  read   decision ledger              # open / closed / unknown per post, buttons, settled closure time
         accepted replies             # chunk progress, incl. each reply's own state + retitle
         Jev verdict log              # one verdict per judged message (newest only is judged)
         live title, Discord waits    # cooldowns.json, stamped when Discord answered
  plan   marker  = ❓ > ⚠️ > ⏳ > ✅ > none
         base    = captain's words > Jev rename on drift > live base
  gate   unknown input or unclear key check -> no write
         10-min pace, except decision-button ❓ and a correction of our own raced write
  compare live title, newest reply, ledger, verdict again -> changed? replan
  write  record the attempt, PATCH, record the landing
contrib/hermes-gateway-firstmate-comms/
├── thread_title.py          # changed: the reconciler (plan, compare-and-write, Discord waits)
├── thread_autoname.py       # new: background judge scan + one-time catch-up (no title writes)
└── outbox_poster.py         # changed: keeps each reply's title input in chunk progress; wakes the worker
bin/
├── fm-jev-lib.sh            # new: shared Jev client (also used by typed dispatch)
├── fm-ext-thread-judge.sh   # new: Jev status + topic fit; --check prints on/off/unknown/inactive
├── fm-ext-thread-name.sh    # new: "<Project> · <topic>" proposal on drift
└── fm-ext-decision.sh       # changed: threads summary with unknown state and closure time; settles free-text posts too

Choices where the spec is silent:

  1. With judging off (no Jev key), a reply's explicit state and retitle feed the same reconciler; with judging on they do not touch the title.
  2. The 10-minute pace covers every change except the marker of a decision-button ❓ and a correction of our own raced write.
  3. Only a marker the captain removes is respected until our marker changes; a swapped marker is replaced.
  4. A question asked while a decision was open belongs to that decision: a kept "done" survives reminders and lands after closure; the question shows no marker after closure.
  5. Closure time is the decision sweep's settle record (up to one 30-second sweep late, accepted); a question posted inside that window counts as the decision's own.
  6. A permanent Discord refusal waits for the thread's next reply; transient failures and unreadable inputs retry after 30 seconds.
  7. The Jev key is stripped from every gateway subprocess except the judge.
  8. bin/fm-ext-topic.sh --retitle-file is removed: nothing calls it.

Evidence

  • Before: main and the parked branch had several writers of a thread's title, so a judge result, the decision sweep, and catch-up could race each other; the first rebuild of this branch (title inputs held only in memory) failed review on write races and restart loss.
    After: tests/fm-ext-thread-autoname.test.sh 13/13 at 2176be0 on a fake clock and a local Discord, among them:
judge worker, judge scan, decision sweep -> 0 PATCH; post marks thread due -> 1 PATCH   (test 1)
running -> done(pace) -> blocked; reset header and 429 hold even the button ❓          (test 4)
done during decision + reminder; close -> ✅ at next slot, not ❓                      (test 5)
chunk accepted / captain renames between compare reads -> no PATCH                     (tests 6, 7b)
kill judge scan at Jev call 1 and 4 -> 12 calls total, 2 repeats, 10 renames           (test 8)
reply accepted mid-PATCH -> next pass corrects without the 10-min pace                 (test 13; fails with correction disabled)

Other suites at 2176be0 (local runs): topic-threads 41, decision 23, bridge all (with FM_TASK_ID unset), dispatch-resolve, thread-context, ask, needs-you-buttons, plugin-dest.
After the pipeline's review fixes (09c9838) its test step reran thread-autoname, topic-threads, dispatch-resolve, bridge 51-52, and a local-gateway drive of 8 scenarios: all passed.

  • CI: the pre-existing main failures (Behavior portable serial 2, 6, 9 and Behavior tests (Herdr), caused by the ubuntu-latest move to 26.04) are fixed on main by the runner pin in ci: pin Linux jobs to ubuntu-24.04 #330; this PR is rebased onto it. The one failure this PR caused (serial 4, bot-identity test using the old title transport) was fixed in the pipeline's CI round.
  • Live, dedicated test channel, real Discord and Jev (2026-11-24 UTC):
Scenario Thread Result
Plain question, no button 1574593924771750050 ❓ at 01:14:17
Decision button, then "done" and a reminder during it, then closure 1574593975690596405 ❓ at once (01:14:29), stayed through the reminder, ✅ at 01:24:50 right after settled closure
Captain rename, then a decision hit by Discord's 429 (wait 599 s) 1574594047706796083 ❓ Captain words · rename check at 01:24:43
Catch-up killed at its second Jev call, then restarted twice 3 threads restart judged only the 2 unjudged threads; third start judged none

Merge Danger

Door: two-way

Revert restores the previous rename path; the new state (state/ext-autoname/catch-up.json, cooldowns.json, title fields in thread records) is ignored by older code.

Blast Radius: Discord-titles

Only topic-thread titles in the dedicated channel change; replies, decision buttons, and routing are untouched, and every title-path failure leaves the title as it is.
Settled free-text decision posts now get a settle record and an empty .finalized marker.

Deferred review findings (follow-up issue)

The last review round was capped by decision; these are listed for a follow-up, not fixed here.
Two came from the last fix round itself and should go first:

  • request-slot-wait-invalidates-title-compare: a PATCH that waits for the shared request slot can overwrite a captain rename made during the wait.
  • retention-fix-expires-actively-renamed-threads: real title writes no longer refresh the thread record's age, so a thread still active under newer requests can age out with its first request.

Also deferred: decision-chronology-loses-opening-and-closing-order, unreadable-ledger-becomes-authoritative-state, kept-status-jumps-unjudged-substantive-post, repeated-manual-edits-reuse-stale-observation, catch-up-freezes-before-legacy-ownership-proof, judge-scan-starts-superseded-cutoffs, permanent-refusal-retries-before-next-reply, key-read-failure-still-enables-explicit-fallback, paced-decision-marker-becomes-held-status, identity-route-cooldown-is-thread-local, forced-safety-sweeps-mask-missing-deadline-wakeups, unused-last-pass-timestamp.
The review on the rebase onto main raised 7 more, also listed, not fixed. One is a public-safety gap to decide before merge:

  • model-retitle-publishes-forbidden-branch-name: when the topic drifts, the naming model can propose a public title containing a branch name mentioned in the thread, and the title screen does not reject it.

Also from that review: retitle-base-can-set-marker-without-verdict, closed-decision-question-can-regain-marker-on-first-delivery, outbox-expiry-rewinds-title-inputs, background-title-scans-block-delivery-progress, opened-thread-lookup-oracle-reuses-receipt, redundant-env-change-test-selector.
The review on the test-step rerun raised 4 more, also listed, not fixed: unrelated-reply-bypasses-title-pace (a reply with no title input that lands during a write can later let another reply skip the 10-minute pace), closure-test-accepts-observation-time, redundant-existing-thread-name-branch, redundant-judging-state-alias.
Declined: superseded-fixed-retry-path (the documented 30-second retry stays).

No-Mistakes review outcomes

No GitHub reviews or review threads exist on this PR; these are the pipeline review findings.

Finding Outcome
decision-marker-becomes-held-status fixed by the pipeline
verdict-cap-evicts-kept-done fixed by the pipeline
safety-sweep-prevents-thread-record-expiration fixed by the pipeline (its follow-on regression is deferred above)
unused-decision-copy-expands-ledger-sweep fixed by the pipeline
positive-reset-test-misses-early-patch fixed by the pipeline
compare-misses-new-verdict-at-same-cutoff fixed by the pipeline
title-http-cooldown-boundary fixed by the pipeline (its follow-on regression is deferred above)
unused-title-bookkeeping-fields fixed by the pipeline
superseded-fixed-retry-path declined
14 others deferred to the follow-up issue
7 from the review on the rebase onto main deferred to the follow-up issue
4 from the review on the test-step rerun deferred to the follow-up issue

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 4 issues (1 error, 3 warnings)
  • 🚨 contrib/hermes-gateway-firstmate-comms/thread_title.py:495 - The approved rule says “at most 1 judged title change per thread per 10 minutes,” with an exception for correcting a raced write. If a state-less follow-up lands during a PATCH to ✅, line 495 treats its newer message ID as evidence of a race even though it leaves the desired title unchanged. The next pass exits at line 660 without clearing that evidence. A later explicit none reply can then take the correction branch at lines 674–675 and remove ✅ inside the ten-minute window. The same path exists with judging on if the intervening post has no verdict and the later post supplies one. At the shared correction check, require the input that made the previous title wrong to have arrived before that write landed.
  • ⚠️ tests/fm-ext-thread-autoname.test.sh:684 - The closure test accepts any positive last_closed_at. A ledger that reports the time of the summary read would pass, even though the contract requires the settled timestamp. Use the fake clock at settlement on lines 675–678 as the expected value, then advance the clock before reading the summary and assert that both last_closed_at and the post's closed_at retain the settlement time.
  • ⚠️ contrib/hermes-gateway-firstmate-comms/outbox_poster.py:1043 - The new title-flag suppression branch in thread_name_for has no required production caller. The request creation path returns an existing thread at line 1341, and the opened-thread path does the same at lines 1420–1424. Remove the extra record lookup and pass the creating title directly.
  • ⚠️ contrib/hermes-gateway-firstmate-comms/thread_title.py:759 - The reconciler adds a second judging_state entry point that only forwards to thread_autoname.judging_state. No intent requirement needs the alias. Remove it and call the shared check from the reconciler entry points at lines 617 and 812.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Post synthetic replies in localhost Discord and see the expected title markers with judging on or off ✅ pass live Live scenario results, explicit_input_with_no_key and catchup_restart. Local protocol transcript, PACE-START.
Post and resolve a synthetic decision in localhost Discord and see the title respect both rate limits and pacing ✅ pass live Live scenario results, marker_precedence_discord_global_wait_and_ledger_closure and success_response_headers_gate_decision_button_patch.
Send a synthetic reply while Jev is pending and see the older verdict discarded after the first chunk lands in localhost Discord ✅ pass live Live scenario results, delivery_is_independent_and_newer_partial_reply_invalidates_older_verdict. Local protocol transcript, FRESHNESS-NEW-FINAL.
Rename a synthetic thread and remove its marker in localhost Discord, then see topic drift preserve the captain’s wording ✅ pass live Live scenario results, manual_words_and_removal_survive_topic_drift and naming_updates_only_unclaimed_base_and_service_failures_keep_titles.
Interrupt initial judging of eleven synthetic localhost Discord threads and see catch-up resume from the saved ten ✅ pass live Live scenario results, catchup_restart. Hermes gateway lifecycle.
Trigger synthetic model, key-check, and Discord failures and observe title preservation and recovery in localhost Discord ✅ pass live Live scenario results, naming_updates_only_unclaimed_base_and_service_failures_keep_titles, discord_refusal_waits_for_next_reply_and_lost_ack_preserves_pace, and unclear_key_check_blocks_both_explicit…
Send a newer synthetic reply while a localhost Discord title write is in flight and see the gateway correct the title promptly ✅ pass live Live scenario results, reply_accepted_during_patch_corrects_title_without_waiting_for_pace. Local protocol transcript, IN-FLIGHT-WRITE-RECHECK.
Use the dedicated Discord test channel and observe the title in the Discord client ⏸️ untested no This phase exercised the real gateway through localhost. Repeating the Discord-client check requires a dedicated channel and bot profile, test credentials, and authority to send traffic to that channe…
  • env -u FM_TASK_ID PYTHONDONTWRITEBYTECODE=1 TMPDIR="$PWD/.gate-title-test/tmp" bash tests/fm-ext-thread-autoname.test.sh
  • env -u FM_TASK_ID PYTHONDONTWRITEBYTECODE=1 TMPDIR="$PWD/.gate-title-test/tmp" bash tests/fm-ext-bot-identity.test.sh
  • env -u FM_TASK_ID PYTHONDONTWRITEBYTECODE=1 TMPDIR="$PWD/.gate-title-test/tmp" bash tests/fm-ext-topic-threads.test.sh
  • bin/fm-hermes-sandbox.sh --root &#34;$PWD/.gate-title-test/run/sandbox&#34; -- hermes gateway run with a workspace-local Discord runtime
  • python3 -B .gate-title-test/emulator.py and python3 -B .gate-title-test/drive.py for live gateway, REST, WebSocket, persisted state, and restart checks
  • python3 -B .gate-title-test/drive.py stale_delivery discord_response_headers discord_failures_and_unknown raced_write followed by python3 -B .gate-title-test/drive.py stale_delivery for corrected fixture checks
  • Captured protocol events, persisted ledger and title results, and gateway lifecycle logs, then verified that all disposable processes exited.
⏭️ **Document** - skipped

Step was skipped.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

dnth added 7 commits November 24, 2026 13:25
- thread_title.py is the only writer of a thread's title: it computes the desired title from its inputs (open decisions from the decision ledger, the latest verdict with its transcript cutoff, a new base, the captain's own words) and writes only when it differs.
- Marker precedence is question > blocked > running > done; a decision button's question mark skips our 10-minute pace, nothing skips Discord's rate-limit headers or 429 retry_after.
- thread_autoname.py judges each post off the delivery path with Jev and the naming model, and runs the one-time, resumable catch-up over the ten newest threads; delivery, the decision sweep, and catch-up only update inputs.
- Shared Jev client and key check in bin/fm-jev-lib.sh; gateway subprocesses no longer receive the key except the judge.
- fm-ext-decision.sh threads reports the newest closure time from the decision post ledger.
- The reconciler now logs the retry_after it waits, so a held title is visible in the gateway journal.
- Each pass recomputes the title from durable state: the decision ledger, accepted-chunk
  progress with each reply's own state and retitle, the thread's Jev verdict log, and
  Discord waits in state/ext-autoname/cooldowns.json.
- Compare-and-write re-reads the live title, newest accepted message, and ledger right
  before PATCH; a write that still raced newer state is corrected on the next pass
  without the 10-minute pace.
- Only the newest unjudged Firstmate message per thread is judged; catch-up fixes its
  ten threads and a horizon before the first model call.
- Events plus a 10-minute safety sweep (also at start) schedule passes.
- fm-ext-thread-judge.sh --check prints on/off/unknown/inactive; unknown decision
  state, unreadable inputs, or an unclear check mean no title work.
- fm-ext-decision.sh settles closed decision posts without buttons too, so each
  closed post keeps one closure time.
@dnth
dnth force-pushed the fm/fm-thread-autorename-v2 branch from d840f15 to 00e925a Compare November 24, 2026 05:31
@dnth
dnth merged commit bf92cd5 into main Nov 24, 2026
25 checks passed
@dnth
dnth deleted the fm/fm-thread-autorename-v2 branch November 24, 2026 11:50
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