-
Notifications
You must be signed in to change notification settings - Fork 3.3k
fix(agent): follow-up review fixes for tinyagents parity (#4451–#4469) #4504
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
Changes from all commits
812a507
7f730a0
01e5cd7
7180329
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -151,6 +151,10 @@ export type SubagentTranscriptItem = | |
| displayName?: string; | ||
| /** Server-computed contextual detail (path / recipient / query). */ | ||
| detail?: string; | ||
| /** Plain-language failure explanation for a FAILED child tool call | ||
| * (#4459) — kept on the transcript item so the rendered live path (not | ||
| * just the fallback `toolCalls` list) shows the why/next copy. */ | ||
| failure?: ToolFailureExplanation; | ||
| }; | ||
|
|
||
| /** One child tool call performed by a running sub-agent. */ | ||
|
|
@@ -730,6 +734,7 @@ function subagentTranscriptItemFromPersisted( | |
| outputChars: item.outputChars, | ||
| displayName: item.displayName, | ||
| detail: item.detail, | ||
| failure: item.failure, | ||
| }; | ||
| } | ||
| return { kind: item.kind, iteration: item.iteration, text: item.text }; | ||
|
|
@@ -1109,16 +1114,21 @@ const chatRuntimeSlice = createSlice({ | |
| elapsedMs?: number; | ||
| outputChars?: number; | ||
| result?: string; | ||
| failure?: ToolFailureExplanation; | ||
| }> | ||
| ) => { | ||
| const { threadId, rowId, callId, success, elapsedMs, outputChars, result } = action.payload; | ||
| const { threadId, rowId, callId, success, elapsedMs, outputChars, result, failure } = | ||
| action.payload; | ||
| const entry = state.toolTimelineByThread[threadId]?.find(e => e.id === rowId); | ||
| const item = entry?.subagent?.transcript?.find(i => i.kind === 'tool' && i.callId === callId); | ||
| if (!item || item.kind !== 'tool') return; | ||
| item.status = success ? 'success' : 'error'; | ||
| if (elapsedMs != null) item.elapsedMs = elapsedMs; | ||
| if (outputChars != null) item.outputChars = outputChars; | ||
| if (result != null) item.result = result; | ||
| // Carry the structured why/next onto the rendered transcript item; a | ||
| // successful result clears any stale failure (#4459). | ||
| item.failure = success ? undefined : failure; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a sub-agent child tool fails in the normal transcript-present path, this only stores Useful? React with 👍 / 👎. |
||
| }, | ||
| setTaskBoardForThread: ( | ||
| state, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,36 @@ fn workspace_write_lock(workspace_dir: &Path) -> Arc<tokio::sync::Mutex<()>> { | |
| ) | ||
| } | ||
|
|
||
| /// Acquire an **inter-process** advisory write lock for `workspace_dir` (#4458). | ||
| /// | ||
| /// [`WORKSPACE_WRITE_LOCKS`] only serializes writers inside this OS process, but | ||
| /// cron launches work via separate `tokio::process::Command` subprocesses that | ||
| /// don't share that mutex — so two cron runs could still clobber the same | ||
| /// `MEMORY.md` mid read-modify-write. This takes an `fs2` exclusive `flock` on a | ||
| /// sentinel `.memory-write.lock` file in the workspace; the returned `File` | ||
| /// holds the lock until it is dropped (end of the write). `flock` acquisition | ||
| /// blocks, so it runs on a blocking thread. | ||
| async fn acquire_cross_process_write_lock(workspace_dir: &Path) -> anyhow::Result<std::fs::File> { | ||
| let lock_path = workspace_dir.join(".memory-write.lock"); | ||
| tokio::task::spawn_blocking(move || { | ||
| use fs2::FileExt; | ||
| if let Some(parent) = lock_path.parent() { | ||
| let _ = std::fs::create_dir_all(parent); | ||
| } | ||
| let file = std::fs::OpenOptions::new() | ||
| .create(true) | ||
| .write(true) | ||
| .truncate(false) | ||
| .open(&lock_path) | ||
|
Comment on lines
+64
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If a workspace already contains Useful? React with 👍 / 👎. |
||
| .map_err(|e| anyhow::anyhow!("open workspace lock file {lock_path:?}: {e}"))?; | ||
| file.lock_exclusive() | ||
| .map_err(|e| anyhow::anyhow!("acquire workspace write flock: {e}"))?; | ||
| Ok::<std::fs::File, anyhow::Error>(file) | ||
| }) | ||
| .await | ||
| .map_err(|e| anyhow::anyhow!("workspace lock task join failed: {e}"))? | ||
| } | ||
|
|
||
| /// Atomically replace `path`'s contents with `content`. | ||
| /// | ||
| /// Writes to a sibling temp file in the same directory (so the rename stays on | ||
|
|
@@ -218,9 +248,13 @@ impl Tool for UpdateMemoryMdTool { | |
| // write so no interleaving append can be lost. | ||
| let lock = workspace_write_lock(&workspace_dir); | ||
| let _guard = lock.lock().await; | ||
| // Also take a cross-process advisory lock so cron subprocesses (which | ||
| // don't share the in-process mutex above) can't clobber the same file | ||
| // mid-RMW. Held across read + atomic write; released on drop. | ||
| let _file_lock = acquire_cross_process_write_lock(&workspace_dir).await?; | ||
| tracing::debug!( | ||
| workspace = %workspace_dir.display(), | ||
| "[update_memory_md] acquired per-workspace write lock" | ||
| "[update_memory_md] acquired per-workspace write lock (in-process + cross-process flock)" | ||
| ); | ||
|
|
||
| match action { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.