Skip to content

fix: credentials: block output while running credential tools #261

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

Merged
merged 2 commits into from
Apr 22, 2024

Conversation

g-linville
Copy link
Member

@g-linville g-linville commented Apr 17, 2024

for #256

One of the goals of the credentials framework was to block output to the terminal while running sys.prompt, since it prompts the user directly in the terminal. I originally implemented this by storing the Monitor into the Context and then pulling it out of the Context and running its Pause function in the implementation of sys.prompt. However, this does not work, as credential tools pretty much always have to call sys.prompt with a new gptscript subprocess.

This new implementation instead stores the Pause function inside of the context and calls it within the Engine code prior to running a credential tool. This way, the Monitor is paused in the correct process.

@g-linville
Copy link
Member Author

g-linville commented Apr 17, 2024

Talked with Darren and I'm gonna refactor this a bit. (Edit: refactor complete.)

Signed-off-by: Grant Linville <[email protected]>
Comment on lines +69 to +71
pause := context2.GetPauseFuncFromCtx(ctx)
unpause := pause()
defer unpause()
Copy link
Member Author

Choose a reason for hiding this comment

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

This could technically be simplified down to defer context2.GetPauseFuncFromCtx(ctx)()() but I was afraid that would be too confusing, so I split it into three lines to make it clearer what is happening here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Part of me would love to see this as defer context2.GetPauseFuncFromCtx(ctx)()(), but I think the split is the right idea.

Copy link
Contributor

Choose a reason for hiding this comment

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

And then you'd be a terrible person. What maniac would do a chained function call in a single line defer :)

Comment on lines +69 to +71
pause := context2.GetPauseFuncFromCtx(ctx)
unpause := pause()
defer unpause()
Copy link
Contributor

Choose a reason for hiding this comment

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

Part of me would love to see this as defer context2.GetPauseFuncFromCtx(ctx)()(), but I think the split is the right idea.

@g-linville g-linville merged commit 463fe29 into gptscript-ai:main Apr 22, 2024
1 check passed
@g-linville g-linville deleted the cred-tool-concurrency-fix branch April 22, 2024 18:01
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.

4 participants