Skip to content

A cut output's file stays its outcome's until the store records it; two flaky tests sync on events - #505

Merged
lydakis merged 4 commits into
mainfrom
claude/project-thread-2jed7q
Oct 31, 2026
Merged

lydakis merged 4 commits into
mainfrom
claude/project-thread-2jed7q

Conversation

@lydakis

@lydakis lydakis commented Oct 31, 2026 •

Copy link
Copy Markdown
Owner

Follow-up to #485, from the day-six external review, plus the two timing-dependent tests it flagged.

The gap in #485

A parallel batch records its results in call order. A later call's outcome can therefore sit in the batch's buffer, with its output file already written, while an earlier call keeps running. Once the keeper returned, the file names had left Kept's drop guard and sat in a plain Vec in Outcome.files. If the turn was stopped at that point, the outcome was dropped and the file stayed on disk with no artifact row naming it, so neither prune nor delete would ever find it.

Reproduced on main: the new test leaves TURN-shell-2-stdout behind and fails.

The fix

Outcome.files is now tools::Files. It removes its files when dropped unless the store has recorded them, the way a temporary file goes away unless it is kept. Ownership now lasts through the database handoff:

  • tool_finish calls files.recorded() right after its savepoint commits. This covers every call path, including the batch's ordered writer.
  • The background command path does the same after process_finish.
  • Anything dropped before that, whether in the batch's buffer, the result channel, a queued write, or a write that failed, removes its files on a blocking worker.
  • Copies share one Arc, so the held answers that a group's rollback snapshot clones (Live) never remove the files twice. When there are no files, which is the usual case, it allocates nothing. Kept's own Drop is folded into this type.

What remains: a group commit that fails after the savepoint took the files leaves them on disk. That is the same class as the daemon crash between write and record that #485 already documented.

Flaky tests

Checks

  • cargo fmt --check, cargo clippy -p agent-runtime --all-targets -D warnings, and cargo test -p agent-runtime all pass.
  • Runtime modules test_accounting, test_answered and test_approvals, with bubblewrap and AGENT_TEST_SANDBOX=1: 90 tests OK.
  • The new test fails against main's daemon and passes here.

Perf: when nothing is cut, the cost is one Option check per recorded result and no allocation. A cut call adds one Arc.

Closes #484. Closes #502.

A parallel batch records results in call order, so a later call's outcome
can wait in the batch's buffer, its output file already written, behind an
earlier call still running. Once written, the file names left the cleanup
guard for a plain vector in the outcome: stopping the turn then dropped the
outcome and left the file with no artifact row to find it by, so neither
prune nor delete removed it.

`Outcome.files` is now `Files`, which removes its files when dropped
unless the store recorded them, as a temporary file goes unless kept.
`tool_finish` and the background `process_finish` mark them recorded once
their savepoint commits. Copies share the files through an Arc, so the
held answer a group's rollback snapshot clones doesn't remove them twice;
no files allocates nothing. The keeper's own guard folds into it.

New runtime test: a batch with a slow call beside a large-output one,
stopped after the second wrote its file, leaves no file; it fails on main.

Flaky tests sync on events instead of tight wall-clock bounds:
- #502: the two sandboxed commands each wait for the other's mark, so
  they pass only by running at once, with no 1.1 s bound.
- #484: the lapse test waits for the answered call to start and gives the
  gate two seconds instead of 100 ms.

Closes #484. Closes #502.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g
@lydakis lydakis self-assigned this Oct 31, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-31T07:17:05.848595Z 1ed1af0 New commits
🔒 Security Review ✅ Completed 2026-10-31T07:18:18.056360Z 1ed1af0 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb27dcbdbd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/store/db.rs Resolved
@lydakis
lydakis merged commit 2d71469 into main Oct 31, 2026
5 checks passed
lydakis added a commit that referenced this pull request Oct 31, 2026
* A cut output's file stays its outcome's until the store records it

A parallel batch records results in call order, so a later call's outcome
can wait in the batch's buffer, its output file already written, behind an
earlier call still running. Once written, the file names left the cleanup
guard for a plain vector in the outcome: stopping the turn then dropped the
outcome and left the file with no artifact row to find it by, so neither
prune nor delete removed it.

`Outcome.files` is now `Files`, which removes its files when dropped
unless the store recorded them, as a temporary file goes unless kept.
`tool_finish` and the background `process_finish` mark them recorded once
their savepoint commits. Copies share the files through an Arc, so the
held answer a group's rollback snapshot clones doesn't remove them twice;
no files allocates nothing. The keeper's own guard folds into it.

New runtime test: a batch with a slow call beside a large-output one,
stopped after the second wrote its file, leaves no file; it fails on main.

Flaky tests sync on events instead of tight wall-clock bounds:
- #502: the two sandboxed commands each wait for the other's mark, so
  they pass only by running at once, with no 1.1 s bound.
- #484: the lapse test waits for the answered call to start and gives the
  gate two seconds instead of 100 ms.

Closes #484. Closes #502.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Record #505's matched perf screen

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Memory: a refused cleanup takes back only its own changes

The loss guard reverted the cleanup's whole commit, and with it any fact
another agent saved or removed while the cleanup was open: git kept it in
the refused commit, but memory lost it and nothing told the agent.

`cleanup start` now records which agent runs the cleanup (AGENT_BOT_ID, or
none for the person). A save or removal by anyone else while it is open is
noted in `.cleanup-others` as the fact now stands. When the guard refuses
the cleanup, those facts are put back over the revert, each as its agent
last left it, their folders reindexed and committed, and the refusal says
how many were kept. Snapshot isolation in effect: the guard takes back the
cleanup's writes, never another writer's.

Closes #471.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Memory: note others' changes under the folder lock, store-qualified owner, say when kept facts overfill the index

Review fixes on the refused-cleanup put-back:
- A save or rm hands the cleanup journal the fact as it wrote it while
  the folder is still locked, instead of rereading the file after the
  lock is gone, where the cleanup could have changed it in between.
- The cleanup's owner is AGENT_STORE#AGENT_BOT_ID: bot ids are each
  store's own, and stores under one HOME share its memory.
- When the put-back leaves a folder's index past its limit (the
  cleanup's removals made room for saves the revert brings back
  beside), the refusal says so; nothing saved is dropped to fit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Memory: a cleanup's finish holds every folder's lock through its revert and put-back

A save between put_back reading the journal and replaying it was
overwritten with the older noted text, and a save during the revert
itself could be clobbered. The finish now takes every folder's lock,
in sorted order, from its commit to its end; saves and removals wait
and land after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

---------

Co-authored-by: Claude <[email protected]>
lydakis added a commit that referenced this pull request Oct 31, 2026
* A cut output's file stays its outcome's until the store records it

A parallel batch records results in call order, so a later call's outcome
can wait in the batch's buffer, its output file already written, behind an
earlier call still running. Once written, the file names left the cleanup
guard for a plain vector in the outcome: stopping the turn then dropped the
outcome and left the file with no artifact row to find it by, so neither
prune nor delete removed it.

`Outcome.files` is now `Files`, which removes its files when dropped
unless the store recorded them, as a temporary file goes unless kept.
`tool_finish` and the background `process_finish` mark them recorded once
their savepoint commits. Copies share the files through an Arc, so the
held answer a group's rollback snapshot clones doesn't remove them twice;
no files allocates nothing. The keeper's own guard folds into it.

New runtime test: a batch with a slow call beside a large-output one,
stopped after the second wrote its file, leaves no file; it fails on main.

Flaky tests sync on events instead of tight wall-clock bounds:
- #502: the two sandboxed commands each wait for the other's mark, so
  they pass only by running at once, with no 1.1 s bound.
- #484: the lapse test waits for the answered call to start and gives the
  gate two seconds instead of 100 ms.

Closes #484. Closes #502.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Record #505's matched perf screen

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Memory: a refused cleanup takes back only its own changes

The loss guard reverted the cleanup's whole commit, and with it any fact
another agent saved or removed while the cleanup was open: git kept it in
the refused commit, but memory lost it and nothing told the agent.

`cleanup start` now records which agent runs the cleanup (AGENT_BOT_ID, or
none for the person). A save or removal by anyone else while it is open is
noted in `.cleanup-others` as the fact now stands. When the guard refuses
the cleanup, those facts are put back over the revert, each as its agent
last left it, their folders reindexed and committed, and the refusal says
how many were kept. Snapshot isolation in effect: the guard takes back the
cleanup's writes, never another writer's.

Closes #471.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Memory: note others' changes under the folder lock, store-qualified owner, say when kept facts overfill the index

Review fixes on the refused-cleanup put-back:
- A save or rm hands the cleanup journal the fact as it wrote it while
  the folder is still locked, instead of rereading the file after the
  lock is gone, where the cleanup could have changed it in between.
- The cleanup's owner is AGENT_STORE#AGENT_BOT_ID: bot ids are each
  store's own, and stores under one HOME share its memory.
- When the put-back leaves a folder's index past its limit (the
  cleanup's removals made room for saves the revert brings back
  beside), the refusal says so; nothing saved is dropped to fit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Memory: a cleanup's finish holds every folder's lock through its revert and put-back

A save between put_back reading the journal and replaying it was
overwritten with the older noted text, and a save during the revert
itself could be clobbered. The finish now takes every folder's lock,
in sorted order, from its commit to its end; saves and removals wait
and land after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Triggers: each HOME has labels of its own

launchd keeps one domain per user and systemd one user manager, whatever
HOME is, so a test's or an eval's HOME added its triggers beside the
user's own, under the same labels: a same-named trigger replaced or
removed another HOME's, and one left loaded after its HOME was deleted
fired into nothing.

A trigger's label is now me.lydakis.agent.trigger.TAG.NAME, TAG being
eight hex digits of a hash of HOME (FNV-1a 64, folded to 32 bits, trailing
slash left out). Sonny's start moves each trigger made before labels had
the tag to its tagged label, once, rolling back one that will not load.
A fire whose HOME is gone removes its definition and unloads its own job,
by the label launchd (XPC_SERVICE_NAME) or systemd (its cgroup) runs it
under.

Closes #453.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Triggers: the relabel moves only triggers made from this HOME

systemd's unit folder can be shared by several HOMEs (one absolute
XDG_CONFIG_HOME); a trigger whose definition runs with another HOME is
that HOME's to move, at its own Sonny's start.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

---------

Co-authored-by: Claude <[email protected]>
lydakis added a commit that referenced this pull request Oct 31, 2026
…ne/day-two condition (#520)

* A cut output's file stays its outcome's until the store records it

A parallel batch records results in call order, so a later call's outcome
can wait in the batch's buffer, its output file already written, behind an
earlier call still running. Once written, the file names left the cleanup
guard for a plain vector in the outcome: stopping the turn then dropped the
outcome and left the file with no artifact row to find it by, so neither
prune nor delete removed it.

`Outcome.files` is now `Files`, which removes its files when dropped
unless the store recorded them, as a temporary file goes unless kept.
`tool_finish` and the background `process_finish` mark them recorded once
their savepoint commits. Copies share the files through an Arc, so the
held answer a group's rollback snapshot clones doesn't remove them twice;
no files allocates nothing. The keeper's own guard folds into it.

New runtime test: a batch with a slow call beside a large-output one,
stopped after the second wrote its file, leaves no file; it fails on main.

Flaky tests sync on events instead of tight wall-clock bounds:
- #502: the two sandboxed commands each wait for the other's mark, so
  they pass only by running at once, with no 1.1 s bound.
- #484: the lapse test waits for the answered call to start and gives the
  gate two seconds instead of 100 ms.

Closes #484. Closes #502.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Record #505's matched perf screen

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Memory: a refused cleanup takes back only its own changes

The loss guard reverted the cleanup's whole commit, and with it any fact
another agent saved or removed while the cleanup was open: git kept it in
the refused commit, but memory lost it and nothing told the agent.

`cleanup start` now records which agent runs the cleanup (AGENT_BOT_ID, or
none for the person). A save or removal by anyone else while it is open is
noted in `.cleanup-others` as the fact now stands. When the guard refuses
the cleanup, those facts are put back over the revert, each as its agent
last left it, their folders reindexed and committed, and the refusal says
how many were kept. Snapshot isolation in effect: the guard takes back the
cleanup's writes, never another writer's.

Closes #471.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Memory: note others' changes under the folder lock, store-qualified owner, say when kept facts overfill the index

Review fixes on the refused-cleanup put-back:
- A save or rm hands the cleanup journal the fact as it wrote it while
  the folder is still locked, instead of rereading the file after the
  lock is gone, where the cleanup could have changed it in between.
- The cleanup's owner is AGENT_STORE#AGENT_BOT_ID: bot ids are each
  store's own, and stores under one HOME share its memory.
- When the put-back leaves a folder's index past its limit (the
  cleanup's removals made room for saves the revert brings back
  beside), the refusal says so; nothing saved is dropped to fit.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Memory: a cleanup's finish holds every folder's lock through its revert and put-back

A save between put_back reading the journal and replaying it was
overwritten with the older noted text, and a save during the revert
itself could be clobbered. The finish now takes every folder's lock,
in sorted order, from its commit to its end; saves and removals wait
and land after.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Triggers: each HOME has labels of its own

launchd keeps one domain per user and systemd one user manager, whatever
HOME is, so a test's or an eval's HOME added its triggers beside the
user's own, under the same labels: a same-named trigger replaced or
removed another HOME's, and one left loaded after its HOME was deleted
fired into nothing.

A trigger's label is now me.lydakis.agent.trigger.TAG.NAME, TAG being
eight hex digits of a hash of HOME (FNV-1a 64, folded to 32 bits, trailing
slash left out). Sonny's start moves each trigger made before labels had
the tag to its tagged label, once, rolling back one that will not load.
A fire whose HOME is gone removes its definition and unloads its own job,
by the label launchd (XPC_SERVICE_NAME) or systemd (its cgroup) runs it
under.

Closes #453.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Triggers: the relabel moves only triggers made from this HOME

systemd's unit folder can be shared by several HOMEs (one absolute
XDG_CONFIG_HOME); a trigger whose definition runs with another HOME is
that HOME's to move, at its own Sonny's start.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Trigger tests: an ended one-off keeps its row until its turn is done

Since #442 a sent one-shot's row stays, ended, until its turn is known
to have completed; only Sonny's window and the served tool forget it.
The real-launchd and real-systemd tests still expected an empty list
after the one-off ended itself, so both failed there (neither runs in
CI). They now expect the one ended row.

Closes #511.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Memory eval: a learned condition, day one hears the fact, day two applies it

The day-six review asked whether a fresh lead on day two applies what day
one learned. The memory condition seeds facts by hand; learned installs
the skill, saves nothing, and on day one has a new agent in the project
hear the fact from the person in passing, with nothing to change. Day
two's fresh agent, in the same HOME, gets the task: only what the first
agent chose to save can carry it. Rows record day one's status and the
facts it saved; the summary counts day_one_saved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

* Memory eval: find day two's turn from its accepted event; record the 10-31 run

Day one and day two share a daemon, so day two is not turn 1; the script
waited on /1 and got turn_not_found. Take the turn from the run's
accepted event, record day one's rounds and tokens, and assert both in
the synthetic test (which failed before this change).

docs/MEMORY_EVAL.md gets the 2026-10-31 run on openai/gpt-6.1-sol:
learned 6/6, memory 9/9, none 3/9.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_013jkdGFBzSEQmnVuCCNV83g

---------

Co-authored-by: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants