Skip to content

Retry finished-session uploads from desktop and terminal activity - #129

Merged
iamnotstatic merged 3 commits into
iamnotstatic:mainfrom
iPeluwa:fix/pending-session-delivery
Oct 28, 2026
Merged

iamnotstatic merged 3 commits into
iamnotstatic:mainfrom
iPeluwa:fix/pending-session-delivery

Conversation

@iPeluwa

@iPeluwa iPeluwa commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Finished sessions could stay local indefinitely after an interrupted process or a failed upload. The reaper finalized sessions without sending them, and live activity only submitted the current session when it had new shipped work. Conversations and terminal tools can stay open for days, leaving real work off the leaderboard.

This combines #124 and #125, covers terminal wrappers, and fixes the concurrency issues found during review:

  • Flush when session-start settles or corrects work. Drain finished work on due live ticks in both desktop hooks and terminal wrappers, even when the current session is unshipped or unchanged.
  • Allow only one queue drain per VIBE_DIR using submit.lock, without holding the database lock over network requests. Busy contenders return immediately. Dead owners recover through a separate breaker gate with a holder recheck; live owners are never evicted by age.
  • Read the queue after acquiring the lock and refresh each queued session before sending it, so another event can reopen, correct or delete it safely.
  • Mark a response accepted or permanently rejected only if all local copies of that session are unchanged from the upload snapshot. In-flight corrections remain pending; legacy duplicates settle together without later uploading the smaller copy.
  • Release the flush lock on every return/error path, keep failed uploads pending, preserve attempt throttling and payload deduplication, and avoid auth/network work for an empty queue.
  • Prevent overlapping wrapper polls. Wait for the wrapper's own bounded startup/poll flush before its final snapshot and upload, and share the live network budget between queue and progress requests.

Validation: the complete local suite passes 169/169. Tests cover six synchronized agents uploading each queued session once, same-process overlap, database writes during network waits, 200/400 responses to snapshots corrected in flight, reopening a later queued session, 429 retry, dead/live/pidless owners, legacy duplicate rows, and a child exiting during a background flush. Nine concurrency regressions fail against the previous PR head.

Combined validation: all three revised branches merge cleanly in the order below and pass 192/192 local tests together.

Merge order: 1. #127 (storage) → 2. #129 (this PR) → 3. #128 (ZCode). This replaces the closed #124 and #125. Retries remain opportunistic and need a later session event, wrapper poll or CLI command; no daemon is introduced.

@iamnotstatic

Copy link
Copy Markdown
Owner

The herd is fixed, 8 agents ticking at once now send each queued session once, and latency stays bounded. One thing left: if a session's upload always takes longer than the 1.2s hook budget, the drain stops on it every time, so sessions behind it never go out and it gets resent on every tick. Could the drain try the least recently attempted session first, or move on to the next one after a timeout?

@iPeluwa

iPeluwa commented Oct 26, 2026

Copy link
Copy Markdown
Contributor Author

Good point. Went with least recently attempted first in fe5a4ee. The drain records when it last tried each queued session (in ~/.vibe/submit-attempts.json, kept out of sessions.json so it doesn't affect the unchanged-snapshot check) and sorts by that, then by startedAt. The attempt is recorded before sending, so a hook cut off mid-request still rotates. A session that always outlasts the budget still gets retried each round, but no longer starves the ones behind it. Added a test where one upload always times out and the session queued behind it still goes out on the next drain.

@iamnotstatic
iamnotstatic self-requested a review October 28, 2026 19:31
@iamnotstatic
iamnotstatic merged commit 62e7651 into iamnotstatic:main Oct 28, 2026
3 checks passed
@iamnotstatic iamnotstatic mentioned this pull request Oct 28, 2026
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.

2 participants