-
Notifications
You must be signed in to change notification settings - Fork 0
Park impossible context compaction #1176
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
KeenWill
wants to merge
1
commit into
agent/daemon-live-compaction-no-progress
Choose a base branch
from
agent/daemon-live-compaction-terminal-park
base: agent/daemon-live-compaction-no-progress
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
crates/persistence/migrations/202608210617_goal_execution_failure_recovery.sql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| -- Preserve execution failures that cannot make progress under an unchanged | ||
| -- goal context, so goal disposition can park them instead of scheduling the | ||
| -- ordinary bounded automatic resumption loop. | ||
|
|
||
| CREATE TABLE goal_execution_failure_recovery ( | ||
| turn_id uuid PRIMARY KEY, | ||
| session_id uuid NOT NULL, | ||
| cause_kind text NOT NULL, | ||
| recorded_at timestamptz NOT NULL DEFAULT transaction_timestamp(), | ||
|
|
||
| UNIQUE (turn_id, session_id), | ||
| CONSTRAINT goal_execution_failure_recovery_cause_kind_closed CHECK ( | ||
| cause_kind IN ('context_compaction_input_does_not_fit') | ||
| ), | ||
| CONSTRAINT goal_execution_failure_recovery_turn_fk | ||
| FOREIGN KEY (turn_id, session_id) | ||
| REFERENCES turn_lifecycle (turn_id, session_id) | ||
| ON UPDATE RESTRICT | ||
| ON DELETE RESTRICT | ||
| DEFERRABLE INITIALLY DEFERRED | ||
| ); | ||
|
|
||
| CREATE FUNCTION require_goal_execution_failure_recovery_terminal() | ||
| RETURNS trigger | ||
| LANGUAGE plpgsql | ||
| AS $$ | ||
| BEGIN | ||
| IF NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM turn_lifecycle AS lifecycle | ||
| WHERE lifecycle.turn_id = NEW.turn_id | ||
| AND lifecycle.session_id = NEW.session_id | ||
| AND lifecycle.state_kind = 'terminal' | ||
| AND lifecycle.terminal_disposition_kind = 'failed' | ||
| AND lifecycle.terminal_model_call_id IS NULL | ||
| ) THEN | ||
| RAISE EXCEPTION 'goal execution-failure recovery requires its exact call-free failed turn' | ||
| USING | ||
| ERRCODE = '23514', | ||
| CONSTRAINT = 'goal_execution_failure_recovery_exact_terminal'; | ||
| END IF; | ||
| RETURN NULL; | ||
| END; | ||
| $$; | ||
|
|
||
| CREATE CONSTRAINT TRIGGER goal_execution_failure_recovery_requires_terminal | ||
| AFTER INSERT ON goal_execution_failure_recovery | ||
| DEFERRABLE INITIALLY DEFERRED | ||
| FOR EACH ROW | ||
| EXECUTE FUNCTION require_goal_execution_failure_recovery_terminal(); | ||
|
|
||
| CREATE TRIGGER goal_execution_failure_recovery_is_append_only | ||
| BEFORE UPDATE OR DELETE ON goal_execution_failure_recovery | ||
| FOR EACH ROW EXECUTE FUNCTION reject_immutable_record_change(); | ||
|
|
||
| CREATE FUNCTION reject_goal_execution_failure_recovery_truncate() | ||
| RETURNS trigger | ||
| LANGUAGE plpgsql | ||
| AS $$ | ||
| BEGIN | ||
| RAISE EXCEPTION '% cannot be truncated', TG_TABLE_NAME | ||
| USING ERRCODE = '23514'; | ||
| END; | ||
| $$; | ||
|
|
||
| CREATE TRIGGER goal_execution_failure_recovery_reject_truncate | ||
| BEFORE TRUNCATE ON goal_execution_failure_recovery | ||
| FOR EACH STATEMENT | ||
| EXECUTE FUNCTION reject_goal_execution_failure_recovery_truncate(); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cause-aware selection runs only in the direct failure callback. If the daemon restarts after the failed-turn transaction commits but before that callback disposes the goal,
reconcile_successstill selectsScheduled; likewise, an ambiguous block commit is reread byreconcile_ambiguous_block, which also unconditionally plans automatic resumption. Both paths therefore arm a resume for a turn carryingcontext_compaction_input_does_not_fit, defeating the durable parking behavior and potentially repeating the impossible turn until the attempt budget is exhausted. Reuse the cause-aware selection in both reconciliation paths, deriving the failed turn from the current terminal turn or block provenance.Useful? React with 👍 / 👎.